WARNING: THIS SITE IS A MIRROR OF GITHUB.COM / IT CANNOT LOGIN OR REGISTER ACCOUNTS / THE CONTENTS ARE PROVIDED AS-IS / THIS SITE ASSUMES NO RESPONSIBILITY FOR ANY DISPLAYED CONTENT OR LINKS / IF YOU FOUND SOMETHING MAY NOT GOOD FOR EVERYONE, CONTACT ADMIN AT ilovescratch@foxmail.com
Skip to content

[BUG] iCalendar looses backslashes \\ -> \ #1008

@niccokunzmann

Description

@niccokunzmann

Describe the bug

When a text, e.g. x\\x is made into an ics string and then parsed, it looses half the \.

To reproduce

This is a bit confusing but the problem is with the ICS. You cannot trust your eye, see below!

>>> import icalendar
>>> cal = icalendar.Calendar()
>>> cal.calendar_name = b = r"\\\\\\" # COUNT: 6
>>> cal2 = icalendar.Calendar.from_ical(cal.to_ical())
>>> cal2.calendar_name == b
False
>>> cal2.calendar_name
vText(b'\\\\\\\\\\\\')       # COUNT: 3 ???
>>> len(cal2.calendar_name), len(b)
(3, 6)
>>> str(cal2.calendar_name), len(str(cal2.calendar_name))
('\\\\\\', 3)   # COUNT 3
>>> cal.to_ical()
b'BEGIN:VCALENDAR\r\nNAME:\\\\\\\\\\\\\\\\\\\\\\\\\r\nEND:VCALENDAR\r\n'
>>> print(cal.to_ical().decode())
BEGIN:VCALENDAR
NAME:\\\\\\\\\\\\    # COUNT 12
END:VCALENDAR

Expected behavior

The count of backslashes should stay the same.

Environment

  • Operating system: independent
  • Python version: 3.11
  • icalendar version: main@3afba5d8d6748e786ebd85522dd8309c23054045

Additional context

Found here:

To close the issue

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions