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

Exception when there's no ':' when parsing value #348

Closed
N0ury opened this issue Jan 23, 2022 · 5 comments · Fixed by #502
Closed

Exception when there's no ':' when parsing value #348

N0ury opened this issue Jan 23, 2022 · 5 comments · Fixed by #502
Assignees
Labels
hacktoberfest Issues for participation in the hacktoberfest https://hacktoberfest.com/ tested and needs fix This pull request tests code but needs a contribution to fix the test - TDD

Comments

@N0ury
Copy link
Contributor

N0ury commented Jan 23, 2022

For the following ics file, I have the error:

  File "/usr/local/lib/python3.9/site-packages/icalendar/cal.py", line 330, in from_ical
    name, params, vals = line.parts()
  File "/usr/local/lib/python3.9/site-packages/icalendar/parser.py", line 349, in parts
    values = unescape_string(st[value_split + 1:])
TypeError: unsupported operand type(s) for +: 'NoneType' and 'int'

Here's the ics file:

BEGIN:VCALENDAR
CALSCALE:GREGORIAN
METHOD:PUBLISH
VERSION:2.0
PRODID:-//Sixt//RAC//EN
BEGIN:VFREEBUSY
FREEBUSY;FBTYPE=FREE:20190624T063000Z/20190624T163000Z
ORGANIZER;CN=Sixt SE
UID:SIXT_9879691160
DTSTAMP:20190612T104813Z
END:VFREEBUSY
BEGIN:VEVENT
CLASS:PUBLIC
DESCRIPTION:\nVotre véhicule avec le numéro de réservation xxxxxxxxxxx sera à votre disposition le 24.06.2019 à 08:30 heures (heure locale). Retour prévu : Ferney-Voltaire AP de Genève Cointrin Sect(F), le 24.06.2019 à 18:30 heures.\nVous trouverez des informations relatives à la modification ou à  l'annulation de votre réservation sous http://www.sixt.fr\n
DTSTART:20190624T063000Z
DTSTAMP:20190612T104813Z
DTEND:20190624T163000Z
LOCATION:Sixt Genève Aéroport secteur France, AP de Genève Cointrin Sect(F), 01210 Ferney-Voltaire, FR
PRIORITY:5
TRANSP:TRANSPARENT
SEQUENCE:0
STATUS:CONFIRMED
SUMMARY:Sixt : détails de votre réservation
UID:SIXT_9879691160
BEGIN:VALARM
TRIGGER:-PT30M
ACTION:DISPLAY
DESCRIPTION:\nLe véhicule avec la n° de réservation xxxxxxxxxxx sera à votre disposition entre 24.06.2019 et 08:30 heures (heure locale) à l'agence Genève Aéroport secteur France. Retour prévu : Ferney-Voltaire AP de Genève Cointrin Sect(F), le 24.06.2019 à 18:30 heures.\nTrouver des informations de localisation et modifier / annuler votre  réservation ici: http://www.sixt.fr\n
END:VALARM
END:VEVENT
END:VCALENDAR

This error happens because of the ORGANIZER line in VFREEBUSY.

Here's how I solved it (not sure it is the best way):

--- /usr/local/lib/python3.9/site-packages/icalendar/parser.py.ori	2021-10-19 05:41:33.000000000 +0200
+++ /usr/local/lib/python3.9/site-packages/icalendar/parser.py	2022-01-23 11:15:14.000000000 +0100
@@ -338,6 +338,8 @@
             if not name:
                 raise ValueError('Key name is required')
             validate_token(name)
+            if not value_split:
+                value_split = i
             if not name_split or name_split + 1 == value_split:
                 raise ValueError('Invalid content line')
             params = Parameters.from_ical(st[name_split + 1: value_split],
@jacadzaca
Copy link
Collaborator

Glancing at the code, the proper place to apply the fix seems to be line 329, but chaning it to

if ch in ':;' and not value_split:

breaks tests. @N0ury's fix works and doesn't break them (not sure if that means anything tho), but feels hacky.

@niccokunzmann
Copy link
Member

I created #436 and it shows the error. A fix can be made to the issue_348 branch and when it is green, it gets merged into master.

@niccokunzmann
Copy link
Member

@N0ury would you like to create a PR?

@niccokunzmann niccokunzmann added tested and needs fix This pull request tests code but needs a contribution to fix the test - TDD hacktoberfest Issues for participation in the hacktoberfest https://hacktoberfest.com/ labels Oct 5, 2022
@manuelmuehlig
Copy link

I have the same issue with this ICS file: https://www.mainhausen.de/municipal/downloads/trash/61

The issues makes https://github.com/mampfes/hacs_waste_collection_schedule fail when trying to scrape the waste collection calendar.

N0ury added a commit to N0ury/icalendar that referenced this issue Dec 16, 2022
@N0ury N0ury mentioned this issue Dec 16, 2022
@jacadzaca jacadzaca linked a pull request Dec 16, 2022 that will close this issue
@niccokunzmann niccokunzmann self-assigned this Apr 12, 2023
@niccokunzmann
Copy link
Member

niccokunzmann commented Apr 13, 2023

The fix is released in v5.0.5. It can be backported to 4.x if someone likes to take this on. Thanks @N0ury for your work!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
hacktoberfest Issues for participation in the hacktoberfest https://hacktoberfest.com/ tested and needs fix This pull request tests code but needs a contribution to fix the test - TDD
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants