u01jmg3 / ics-parser

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

Issue with URLs that contain an @ symbol #314

Closed DCox44 closed 1 year ago

DCox44 commented 1 year ago

Trying to figure out an issue, and I believe that it may be the @ symbol in a url causing the issue.

I have tried many different URLs and they all parse correctly except for the one that Outlook provides me when publishing a calendar; it contains an @ symbol. Wondering if you have come across this issue.

s0600204 commented 1 year ago

Not personally, no.

Could you provide an (anonymised) example of a URL that doesn't work, and some description of the parsing failure, please.

Along with the details requested by the Issue Template.

DCox44 commented 1 year ago

Yeah, so I'm working on a custom plugin for my wordpress site. I essentially have a file upload and a URL text field so that I can either upload an ICS or enter in a URL..

This is the URL causing issues https://outlook.office365.com/owa/calendar/10cc3b18eab34ab48430f469dcc10981@county-lambton.on.ca/9a08725d47e84fbf89115df19ce9634f16640673239597688242/calendar.ics

These two URLS work

https://www.calendarlabs.com/ical-calendar/ics/76/US_Holidays.ics https://canada-holidays.ca/ics/ON?cd=true

I can download the ICS from the URL that doesn't work and upload it and it works fine.

The warnings/fatal errors I'm getting are: Warning: file(https://...@county-lambton.on.ca/127c4cd019924e1ba54861f278c0b83518115264385855080647/calendar.ics): failed to open stream: HTTP request failed! HTTP/1.1 400 in C:\wamp64\www\Plugin Development\wp-content\plugins\icsImporter\ICal.php on line 2639

( ! ) Fatal error: Uncaught Exception: The file path or URL 'https://outlook.office365.com/owa/calendar/ceb1ae3ad22a4c66bf2b7293ebc21cfb@county-lambton.on.ca/127c4cd019924e1ba54861f278c0b83518115264385855080647/calendar.ics' does not exist. in C:\wamp64\www\Plugin Development\wp-content\plugins\icsImporter\ICal.php on line 2640

PHP Version: 7.4.26 PHP Timezone: America/Toronto ICS Parser Version: 3.2 Windows/WAMP Server

DCox44 commented 1 year ago

I'm initiating it like this

$ical = new ICal($file); // $file is the URL/File Location given in the form

But have also tried this

$ical = new ICal();
if (substr($file, -4) === '.ics') {
    $ical->initString($file);
} else if (substr($file, -4) === '.tmp') {
    $ical->initFile($file);
} else {
    $ical->initUrl($file);
}

I'm 80% positive I had it working by using initString, but I'm doubting myself because I can't replicate the success.

s0600204 commented 1 year ago

Looking into it this appears to be a quirk of Outlook, where it requires the User Agent string to be set in the request headers.

Try using the "httpUserAgent" argument when creating the ICal object, like so:

$ical = new ICal($url, array("httpUserAgent" => "A User Agent"));
u01jmg3 commented 1 year ago

Related previous issue: #311

@DCox44: I would always suggest looking at previous issues in case your problem has come up before.

u01jmg3 commented 1 year ago

(Note added to README: 10f0df5)

u01jmg3 commented 1 year ago

Closing as I believe the question has been answered