NaturalIntelligence / fast-xml-parser

Validate XML, Parse XML and Build XML rapidly without C/C++ based libraries and no callback.
https://naturalintelligence.github.io/fast-xml-parser/
MIT License
2.49k stars 302 forks source link

Error escaping of line feed introduced from version 3.17.3 #303

Closed matteomattei closed 3 years ago

matteomattei commented 3 years ago

Description

From version 3.17.2 to version 3.17.3 (problem is still present in version 3.17.4) has been added an issue parsing line feed on the first line of a multi line value.

Input

<?xml version="1.0" encoding="utf-8"?><n1:schedule-response xmlns:n1="urn:ietf:params:xml:ns:caldav" xmlns:D="DAV:"><n1:response><n1:request-status>2.0;Success</n1:request-status><n1:calendar-data>BEGIN:VCALENDAR
PRODID:-//Inverse inc./SOGo 4.3.1//EN
VERSION:2.0
METHOD:REPLY
BEGIN:VFREEBUSY
UID:e5718fd0-3094-11eb-9344-5316989fab61
DTSTAMP:20201127T094242Z
DTSTART:20201128T133000Z
DTEND:20211128T133000Z
FREEBUSY;FBTYPE=BUSY:20201128T133000Z/20201128T143000Z
FREEBUSY;FBTYPE=BUSY-TENTATIVE:20201128T130000Z/20201128T140000Z
END:VFREEBUSY
END:VCALENDAR</n1:calendar-data></n1:response><n1:response><n1:recipient>mailto:maurizio.mambrini@qboxmail.it</n1:recipient><n1:request-status>2.0;Success</n1:request-status><n1:calendar-data>BEGIN:VCALENDAR
PRODID:-//Inverse inc./SOGo 4.3.1//EN
VERSION:2.0
METHOD:REPLY
BEGIN:VFREEBUSY
UID:e5718fd0-3094-11eb-9344-5316989fab61
DTSTAMP:20201127T094242Z
DTSTART:20201128T133000Z
DTEND:20211128T133000Z
FREEBUSY;FBTYPE=BUSY:20201128T130000Z/20201128T140000Z
END:VFREEBUSY
END:VCALENDAR</n1:calendar-data></n1:response></n1:schedule-response>
const fs = require('fs');
const parser = require('fast-xml-parser');

const buf = fs.readFileSync('freebusy.xml').toString();
let a = parser.parse(buf, {trimValues: false});
console.log(a['n1:schedule-response']['n1:response'][0]['n1:calendar-data']);

Output

With version 3.17.3 and 3.17.4 the output is this:

BEGIN:VCALENDAR PRODID:-//Inverse inc./SOGo 4.3.1//EN
VERSION:2.0
METHOD:REPLY
BEGIN:VFREEBUSY
UID:e5718fd0-3094-11eb-9344-5316989fab61
DTSTAMP:20201127T094242Z
DTSTART:20201128T133000Z
DTEND:20211128T133000Z
FREEBUSY;FBTYPE=BUSY:20201128T133000Z/20201128T143000Z
FREEBUSY;FBTYPE=BUSY-TENTATIVE:20201128T130000Z/20201128T140000Z
END:VFREEBUSY
END:VCALENDAR

expected data

With version 3.17.2 the output is correct:

BEGIN:VCALENDAR
PRODID:-//Inverse inc./SOGo 4.3.1//EN
VERSION:2.0
METHOD:REPLY
BEGIN:VFREEBUSY
UID:e5718fd0-3094-11eb-9344-5316989fab61
DTSTAMP:20201127T094242Z
DTSTART:20201128T133000Z
DTEND:20211128T133000Z
FREEBUSY;FBTYPE=BUSY:20201128T133000Z/20201128T143000Z
FREEBUSY;FBTYPE=BUSY-TENTATIVE:20201128T130000Z/20201128T140000Z
END:VFREEBUSY
END:VCALENDAR

Would you like to work on this issue?

Bookmark this repository for further updates.

github-actions[bot] commented 3 years ago

I'm glad you find this repository helpful. I'll try to address your issue ASAP. You can watch the repo for new changes or star it.

amitguptagwl commented 3 years ago

Does #289 solve your issue?

matteomattei commented 3 years ago

Yes, version 3.17.5 fixes the issue. Thanks!!!