u01jmg3 / ics-parser

Parser for iCalendar Events • PHP 8+, 7 (≥ 7.4), 5 (≥ 5.6)
MIT License
439 stars 144 forks source link

Undefined array key warning if DESCRIPTION contains HTML ampersand entities #317

Closed room34 closed 1 year ago

room34 commented 1 year ago

Description of the Issue:

If the .ics file contains an ampersand entity in the DESCRIPTION (though I suspect the issue may just be the semicolon), I get the following PHP warnings:

Warning: Undefined array key 4 in /var/www/.../ics-parser/src/ICal/ICal.php on line 1033

Warning: Undefined array key 4 in /var/www/.../ics-parser/src/ICal/ICal.php on line 1042

(The attached file has a .txt extension appended so GitHub will accept the upload.) AmpersandEntityExample.ics.txt

Steps to Reproduce:

Use attached example which contains an HTML ampersand entity in the DESCRIPTION. This is an actual example from one of my users, with all events other than the one containing the ampersand entity removed.

u01jmg3 commented 1 year ago

Thanks for logging this issue. A PR is welcome.

room34 commented 1 year ago

I have a workaround for now, but I don't know the code base well enough to offer a proper fix. My workaround (PHP >= 7) is to just append ?? '' to these lines.

u01jmg3 commented 1 year ago

?? can be rewritten as just a standard ternary (is_null($var) ? $var : '')

room34 commented 1 year ago

I see that the change committed is only accounting for non-breaking spaces but not other HTML ampersand entities. Did you confirm that it was only nbsp’s that were causing the problem?

u01jmg3 commented 1 year ago

I've focussed on the non-breaking space for now as it affects the unfolding mechanism that's permitted in the iCal spec.