Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix handling of single strings passed to vCategory #566

Merged
merged 2 commits into from
Oct 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ New features:

Bug fixes:

- CATEGORIES field now accepts a string as argument
Ref: #322
[jacadzaca]
- Multivalue FREEBUSY property is now parsed properly
Ref: #27
[jacadzaca]
Expand Down
2 changes: 1 addition & 1 deletion src/icalendar/prop.py
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,7 @@ def from_ical(ical, timezone=None):
class vCategory:

def __init__(self, c_list):
if not hasattr(c_list, '__iter__'):
if not hasattr(c_list, '__iter__') or isinstance(c_list, str):
c_list = [c_list]
self.cats = [vText(c) for c in c_list]

Expand Down
6 changes: 6 additions & 0 deletions src/icalendar/tests/calendars/issue_322_expected_calendar.ics
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
BEGIN:VCALENDAR
BEGIN:VEVENT
SUMMARY:Event with bare string as argument for categories
CATEGORIES:Lecture
END:VEVENT
END:VCALENDAR
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
from icalendar import Calendar, Event


def test_issue_322_single_string_split_into_multiple_categories(calendars):
calendar = Calendar()
event = Event()
event.add('summary', 'Event with bare string as argument for categories')
event.add('categories', "Lecture")
calendar.add_component(event)
assert calendar.to_ical() == calendars.issue_322_expected_calendar.raw_ics