From 0e06a37b58fe6c6b651206a7dbef01592183e09d Mon Sep 17 00:00:00 2001 From: jaca Date: Sat, 30 Sep 2023 16:05:17 +0200 Subject: [PATCH] fix #322 --- CHANGES.rst | 4 +++- src/icalendar/prop.py | 2 +- .../tests/calendars/issue_322_expected_calendar.ics | 6 ++++++ ...trings_characters_split_into_multiple_categories.py | 10 ++++++++++ 4 files changed, 20 insertions(+), 2 deletions(-) create mode 100644 src/icalendar/tests/calendars/issue_322_expected_calendar.ics create mode 100644 src/icalendar/tests/test_issue_322_single_strings_characters_split_into_multiple_categories.py diff --git a/CHANGES.rst b/CHANGES.rst index 7d0b6da4..c3a86018 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -20,7 +20,9 @@ New features: Bug fixes: -- ... +- CATEGORIES field now accepts strings properly + Ref: #322 + [jacadzaca] 5.0.10 (unreleased) ------------------- diff --git a/src/icalendar/prop.py b/src/icalendar/prop.py index b4448c6c..42cc321a 100644 --- a/src/icalendar/prop.py +++ b/src/icalendar/prop.py @@ -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] diff --git a/src/icalendar/tests/calendars/issue_322_expected_calendar.ics b/src/icalendar/tests/calendars/issue_322_expected_calendar.ics new file mode 100644 index 00000000..cdfbe6fb --- /dev/null +++ b/src/icalendar/tests/calendars/issue_322_expected_calendar.ics @@ -0,0 +1,6 @@ +BEGIN:VCALENDAR +BEGIN:VEVENT +SUMMARY:Event with bare string as argument for categories +CATEGORIES:Lecture +END:VEVENT +END:VCALENDAR diff --git a/src/icalendar/tests/test_issue_322_single_strings_characters_split_into_multiple_categories.py b/src/icalendar/tests/test_issue_322_single_strings_characters_split_into_multiple_categories.py new file mode 100644 index 00000000..f4e539fc --- /dev/null +++ b/src/icalendar/tests/test_issue_322_single_strings_characters_split_into_multiple_categories.py @@ -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