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

[BUG] Issues using vBoolean and others for parameters #500

Closed
4 of 5 tasks
tisdall opened this issue Dec 14, 2022 · 2 comments · Fixed by #501
Closed
4 of 5 tasks

[BUG] Issues using vBoolean and others for parameters #500

tisdall opened this issue Dec 14, 2022 · 2 comments · Fixed by #501

Comments

@tisdall
Copy link

tisdall commented Dec 14, 2022

Describe the bug

I'm new to using this library so it's possible I'm misunderstanding how these property types are being used. I was trying to add an rsvp parameter to an attendee as a vBoolean and got a stacktrace.

The docs talk about doing it this way:

Automatic encoding is not yet implemented for parameter values, so you must use the ‘v*’ types you can import from the icalendar package (they’re defined in icalendar.prop):

Looking through the code, it seems like this issue exists for any of the property types that are not based on str, list, or tuple. list and tuple go through q_join() while everything else goes through dquote() which requires it to have a str.replace() method.

def param_value(value):
"""Returns a parameter value.
"""
if isinstance(value, SEQUENCE_TYPES):
return q_join(value)
return dquote(value)

To Reproduce

from icalendar import Event, vBoolean, vCalAddress
attendee = vCalAddress(f'mailto:someone@example.com')
attendee.params['rsvp'] = vBoolean(True)
event = Event()
event.add('attendee', attendee, encode=0)
print(event.to_ical().decode())

Output:

(file paths reduced to make it easier to read)

Traceback (most recent call last):
  File "<console>", line 1, in <module>
  File "icalendar/cal.py", line 430, in to_ical
    content_lines = self.content_lines(sorted=sorted)
  File "icalendar/cal.py", line 419, in content_lines
    cl = self.content_line(name, value, sorted=sorted)
  File "icalendar/cal.py", line 412, in content_line
    return Contentline.from_parts(name, params, value, sorted=sorted)
  File "icalendar/parser.py", line 315, in from_parts
    return cls(f'{name}:{values}')
  File "icalendar/parser.py", line 218, in to_ical
    value = param_value(value)
  File "icalendar/parser.py", line 105, in param_value
    return dquote(value)
  File "icalendar/parser.py", line 144, in dquote
    val = val.replace('"', "'")
AttributeError: 'vBoolean' object has no attribute 'replace'

Expected behavior

BEGIN:VEVENT
ATTENDEE;RSVP=TRUE:mailto:someone@example.com
END:VEVENT

Environment

  • OS: MacOS 13.1
  • Python version: 3.9.13
  • icalendar version: 5.0.3

Additional context

  • I tested it with the latest version pip3 install https://github.com/collective/icalendar.git
  • I attached the ICS source file or there is no ICS source file
@jacadzaca
Copy link
Collaborator

Thanks for reporting :) This is definitely not an expected behavior and should be fixed. For now, please use this as a workaround:

from icalendar import Event, vText, vCalAddress
attendee = vCalAddress(f'mailto:someone@example.com')
attendee.params['rsvp'] = vText('TRUE')
event = Event()
event.add('attendee', attendee, encode=0)
print(event.to_ical().decode())

Output:

BEGIN:VEVENT
ATTENDEE;RSVP=TRUE:mailto:someone@example.com
END:VEVENT

jacadzaca added a commit that referenced this issue Dec 15, 2022
jacadzaca added a commit that referenced this issue Dec 15, 2022
This was referenced Dec 15, 2022
@niccokunzmann
Copy link
Member

Thanks! The fix is in version 5.0.4, ready to install.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants