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

Unable to read DESCRIPTION field with \n characters #217

Open
mrkmhny opened this issue Aug 31, 2022 · 5 comments
Open

Unable to read DESCRIPTION field with \n characters #217

mrkmhny opened this issue Aug 31, 2022 · 5 comments

Comments

@mrkmhny
Copy link

mrkmhny commented Aug 31, 2022

Example...

// import ical
const ical = require('node-ical');

// use the sync function parseFile() to parse this ics file
const events = ical.sync.parseFile('example-calendar.ics');
// loop through events and log them
for (const event of Object.values(events)) {
    console.log(
        'Summary: ' + event.summary +
        '\nDescription: ' + event.description +
        '\nStart Date: ' + event.start.toISOString() +
        '\n'
    );
};
const directEvents = ical.sync.parseICS(`
BEGIN:VCALENDAR
VERSION:2.0
CALSCALE:GREGORIAN
BEGIN:VEVENT
SUMMARY:Hey look! An example event!
DTSTART;TZID=America/New_York:20130802T103400
DTEND;TZID=America/New_York:20130802T110400
LOCATION:1000 Broadway Ave.\, Brooklyn
DESCRIPTION: Do \nsomething in NY.
STATUS:CONFIRMED
UID:7014-1567468800-1567555199@[email protected]
END:VEVENT
END:VCALENDAR
`);
// log the ids of these events
console.log(Object.keys(directEvents));

... will only parse "Do " from the description because node-ical interprets the newline as the start of a new field

@wodka
Copy link
Contributor

wodka commented Jun 12, 2023

Based on how this looks -> you should have escaped the \n - else it will be passed as an actual newline putting "something in NY." into the next line

@mrkmhny
Copy link
Author

mrkmhny commented Jun 12, 2023

Based on how this looks -> you should have escaped the \n - else it will be passed as an actual newline putting "something in NY." into the next line

The \n in this case is coming from the Description text box inside of confluence. There isn't any opportunity to escape the newline because it's just a simple plain text box in the UI. Image below

Screenshot 2023-06-12 at 10 55 51 AM

@wodka
Copy link
Contributor

wodka commented Jun 12, 2023

if the ”\n" is part of the ical then it is fine, I'm just referring to the JS you posted.

image

-> the \n is within your string passed as an actual new line to parseICS -> therefor only showing up as " Do ".

whereas when you escape the \n with \n it will also extract the correct " Do \nsomething in NY."
image

@mrkmhny
Copy link
Author

mrkmhny commented Jun 12, 2023

if the ”\n" is part of the ical then it is fine, I'm just referring to the JS you posted.

image

-> the \n is within your string passed as an actual new line to parseICS -> therefor only showing up as " Do ".

whereas when you escape the \n with \n it will also extract the correct " Do \nsomething in NY." image

Sorry yeah, I hard coded the ical data for the sake of posting a clear, concise, and reproducible example. In reality this data would be coming from an API call to an external service. So in practice, escaping the \n chars would not be an option.

I've tried hacking together a simple function that could parse the DESCRIPTION field and find/replace all the \n characters, but there wasn't really a reliable/safe way to do this, since it's difficult to differentiate the \n chars that are part of the DESCRIPTION plain text vs the actual \n characters that indicate the next field in the ical data. Not to mention, any other appearance of the string "DESCRIPTION:" in the ical data would also throw off this parsing

@wodka
Copy link
Contributor

wodka commented Jun 12, 2023

Can you perhaps just post the lines of the description where you see the actual failure? (and replace all the non \n text with something else?)

with PRODID:Microsoft Exchange Server 2010 we had a problem recently with something along the following:

DESCRIPTION;LANGUAGE=en-US:
\nand here we do have some text
 and here the next line

does that look like your error? (this is invalid syntax for ical -> meaning not parsing it is correct in this case, we work around with appending a space for every \n that is in the beginning of a line)

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

2 participants