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

error:malformed calendar; expected end #111

Closed
KirillZet opened this issue Nov 12, 2024 · 11 comments
Closed

error:malformed calendar; expected end #111

KirillZet opened this issue Nov 12, 2024 · 11 comments
Assignees

Comments

@KirillZet
Copy link

Current Behavior:

Hello, I'm trying to parse a calendar using your library.
Calendar obtained via http.
Here's my code:

icalURL := "http://english.mirea.ru/schedule/api/ical/1/248"

resp, err := http.Get(icalURL)
if err != nil {
	log.Fatal(err)
}
defer resp.Body.Close()

fmt.Println("Raw iCal data:")
body, err := io.ReadAll(resp.Body)
if err != nil {
	log.Fatal(err)
}
fmt.Println(string(body))

calendar, err := ics.ParseCalendar(strings.NewReader(string(body)))
if err != nil {
	log.Fatal(err)
}

fmt.Println(calendar)

Calendar is nil and error “malformed calendar; expected end”

Expected Behavior:

I tested parsing this calendar(from the same link) in python using the library icalendar, everything parsed as I needed it to.

Steps To Reproduce:

Minimal Example ical extract:

BEGIN:VCALENDAR
PRODID:-//github.com/rianjs/ical.net//NONSGML ical.net 4.0//EN
VERSION:2.0
X-WR-CALNAME:БСБО-01-21
BEGIN:VTIMEZONE
TZID:Europe/Moscow
X-LIC-LOCATION:Europe/Moscow
BEGIN:STANDARD
TZOFFSETFROM:+0300
TZOFFSETTO:+0300
END:STANDARD
END:VTIMEZONE
BEGIN:VEVENT
DTEND;TZID=Europe/Moscow;VALUE=DATE:20240324
DTSTAMP;TZID=Europe/Moscow:00010101T000000
DTSTART;TZID=Europe/Moscow;VALUE=DATE:20240323
SEQUENCE:0
SUMMARY:Все занятия в дистанционном формате
TRANSP:TRANSPARENT
UID:c68bc5ec-e46f-55ae-9f0a-9cea4365dc9b
END:VEVENT
BEGIN:VEVENT
CATEGORIES:ЛК
DESCRIPTION:Преподаватель: Корягин Сергей Викторович\n\nГруппы:\nБСБО-01-2
 1\nБСБО-02-21\nБСБО-04-21\n
DTEND;TZID=Europe/Moscow:20240902T121000
DTSTAMP:00010101T000000
DTSTART;TZID=Europe/Moscow:20240902T104000
LOCATION:455 (С-20)
RRULE:FREQ=WEEKLY;INTERVAL=2;UNTIL=20241230T210000Z
SEQUENCE:0
SUMMARY:ЛК Создание инструментальных средств разработки программного обесп
 ечения
TRANSP:OPAQUE
UID:f9de3adf-37f2-5710-abaf-27bd64443c70
X-SCHEDULE_VERSION-ID:8
END:VEVENT
BEGIN:X-SCHEDULE-VERSION
SVID:8
X-SV-END:2024-12-30T21:00:00.0000000Z
X-SV-START:2024-09-01T21:00:00.0000000Z
X-SV-TYPE:SEMESTER
END:X-SCHEDULE-VERSION
END:VCALENDAR

Anything else:

icalURL := "http://english.mirea.ru/schedule/api/ical/1/248"

@arran4 arran4 self-assigned this Nov 15, 2024
@arran4
Copy link
Owner

arran4 commented Nov 15, 2024

Will do a small test now. See if it can be quickly resolved.

@arran4
Copy link
Owner

arran4 commented Nov 15, 2024

@KirillZet The issue is the _ in this line:

X-SCHEDULE_VERSION-ID:8

Tests:

func TestIssue111(t *testing.T) {
type Test struct {
name string
fn string
}
for _, test := range []Test{
{name: "Just the basis", fn: "base-structure.ics"},
{name: "vtimezone1 section", fn: "vtimezone1.ics"},
{name: "vevent1 section", fn: "vevent1.ics"},
{name: "vevent2 section", fn: "vevent2.ics"},
{name: "scheduleversion section", fn: "scheduleversion.ics"},
{name: "Just the basis", fn: "base-structure.ics"},
{name: "vevent2 without description section", fn: "vevent2-no-desc.ics"},
{name: "vevent2 fixed section", fn: "vevent2-fixed.ics"},
{name: "Full file", fn: "file1.ics"},
} {
t.Run(test.name, func(t *testing.T) {
calFile, err := TestData.Open("testdata/issue111/" + test.fn)
if err != nil {
t.Errorf("read file: %v", err)
}
_, err = ParseCalendar(calFile)
if err != nil {
t.Errorf("parse calendar: %v", err)
}
})
}
}

Broken: https://github.com/arran4/golang-ical/blob/5670d8a3f3650007bb5b3b827b7a3aead774480d/testdata/issue111/vevent2.ics

Working: https://github.com/arran4/golang-ical/blob/5670d8a3f3650007bb5b3b827b7a3aead774480d/testdata/issue111/vevent2.ics

Which should follow the grammar: https://datatracker.ietf.org/doc/html/rfc5545

(I have extracted it to the relevant parts from section 3.1)

     name          = iana-token / x-name
     x-name        = "X-" [vendorid "-"] 1*(ALPHA / DIGIT / "-")
     vendorid      = 3*(ALPHA / DIGIT)

Alpha and digit are defined in:

     ALPHA      = %x41-5A / %x61-7A   ; A-Z / a-z
     DIGIT      = %x30-39

Which I know sucks as an answer.

How much influence do you have over this choice of character? I will see if we can find a solution. It's not per-say a "bug" in this but I do feel that if a work around is possible I could try offer it.

I don't know ical.net should we ping the developer? https://github.com/ical-org/ical.net

@arran4
Copy link
Owner

arran4 commented Nov 15, 2024

Hah.. Clipboard failure.

Try one of those against working: https://github.com/arran4/golang-ical/blob/5670d8a3f3650007bb5b3b827b7a3aead774480d/testdata/issue111/vevent2-no-desc.ics

Remember, always ^C at least 2 times. :P

@KirillZet
Copy link
Author

Thanks for the help)
I just replaced this line everywhere X-SCHEDULE_VERSION-ID:8, with this X-SCHEDULE-VERSION-ID, and everything parsed as it should.

bodyString = strings.Replace(bodyString, "X-SCHEDULE_VERSION-ID:8", "X-SCHEDULE-VERSION-ID:8", -1)

I think everyone who faces the same problem can solve it this way. It's a bit of a crutch, but it works)

@KirillZet
Copy link
Author

Could be in func ParseCalendar(r io.Reader) (*Calendar, error) replace string before parsing to avoid problems with this format

@KirillZet KirillZet reopened this Nov 15, 2024
@KirillZet KirillZet closed this as not planned Won't fix, can't repro, duplicate, stale Nov 15, 2024
@arran4
Copy link
Owner

arran4 commented Nov 16, 2024

I think this ticket indicates 2 issues with my library:

So expect improvements.

@KirillZet were you able to find where the invalid token (name X-SCHEDULE_VERSION-ID:8) was being inserted? What's generating it?

@KirillZet
Copy link
Author

I think this ticket indicates 2 issues with my library:

So expect improvements.

@KirillZet were you able to find where the invalid token (name X-SCHEDULE_VERSION-ID:8) was being inserted? What's generating it?

The API from which I get the link to ical belongs to my university, so there's no way for me to see what's actually going on there.

@arran4
Copy link
Owner

arran4 commented Nov 18, 2024

Ah. I guess all you can do is log it. Good luck.

@KirillZet KirillZet reopened this Dec 19, 2024
@arran4
Copy link
Owner

arran4 commented Dec 19, 2024

@KirillZet You re-opened this, but your message was lost?

@KirillZet
Copy link
Author

Sorry it was an accident, I'll close it now

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

No branches or pull requests

3 participants