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

Support Mac/Linux line endings when unfolding lines #124

Closed
dxdc opened this issue Apr 13, 2017 · 18 comments · Fixed by #128
Closed

Support Mac/Linux line endings when unfolding lines #124

dxdc opened this issue Apr 13, 2017 · 18 comments · Fixed by #128
Labels

Comments

@dxdc
Copy link
Contributor

dxdc commented Apr 13, 2017

  • PHP Version: 5.5.38

Description of the Issue:

Within the ICS file, only the first line of multi-line DESCRIPTION is returned. In this example, only Name: Bill would be returned.

ics snippet

BEGIN:VEVENT
SUMMARY:The event summary
DESCRIPTION:Name: Bill\n
 Facility: Shop1\n
 Shift: Morning\n
 Shift Type: Floor
END:VEVENT

Steps to Reproduce:

See above. Only the first line of the description field is returned.

@u01jmg3 u01jmg3 self-assigned this Apr 13, 2017
@u01jmg3
Copy link
Owner

u01jmg3 commented Apr 13, 2017

  • This is only a partial event but from initial testing the parser correctly returns the complete description.

demo

@dxdc
Copy link
Contributor Author

dxdc commented Apr 14, 2017

Thanks for the reply @u01jmg3. I'm curious, how are you loading this into the EventObject? I wonder if it's because I'm loading it into a file? I get identical behavior with either of the below scripts.

$raw_ics_data = file_get_contents('file.ics');
$ical = new ICal( explode( "\n", $raw_ics_data ) );
$events = $ical->events();
print_r($events);
$ical = new ICal('file.ics');
$events = $ical->events();
print_r($events);

try this: file.ics

BEGIN:VCALENDAR
VERSION:2.0
X-PUBLISHED-TTL:PT5M
PRODID:Testing\, LLC\, domain.com Version 1.0
METHOD:PUBLISH
BEGIN:VEVENT
UID:PRODUCTIONORG462SS208@domain.com
SEQUENCE:2
DTSTAMP:20170413T223147Z
DTSTART:20170301T123000Z
DTEND:20170301T203000Z
SUMMARY:Day S John
DESCRIPTION:Group: University of XYZ\n
 Facility: Facility 1\n
 Shift: Morning South\n
 Shift Type: Cashier
END:VEVENT
END:VCALENDAR

@u01jmg3
Copy link
Owner

u01jmg3 commented Apr 14, 2017

I'm curious, how are you loading this into the EventObject?

I wonder if it's because I'm loading it into a file?


<?php
require_once '../vendor/autoload.php';

use ICal\ICal;

$ical = new ICal('file.ics', array(
    'defaultSpan'           => 2,     // Default value
    'defaultWeekStart'      => 'MO',  // Default value
    'skipRecurrence'        => false, // Default value
    'useTimeZoneWithRRules' => false, // Default value
));

var_dump($ical->events());

u01jmg3 added a commit that referenced this issue Apr 15, 2017
@dxdc
Copy link
Contributor Author

dxdc commented Apr 17, 2017

@u01jmg3 Thanks for continuing to look into this. I had already tested your example script, which has the same behavior, and strangely, it's still not working. Do you think it's a php.ini setting?

Here is the PHP script, with the same file.ics I showed above. The description array is still chopped off. I just made a slight modification to hardcode the timezone in this particular case. Not sure if it matters, but I've tested this both on Mac and Linux.

PHP 5.6.29 (cli) (built: Dec  8 2016 23:03:30) 
Copyright (c) 1997-2016 The PHP Group
Zend Engine v2.6.0, Copyright (c) 1998-2016 Zend Technologies
<?php
require_once __DIR__.'/vendor/autoload.php';

use ICal\ICal;

if ( !ini_get( 'date.timezone' ) )
            date_default_timezone_set( 'America/Chicago' );

$ical = new ICal('file.ics', array(
    'defaultSpan'           => 2,     // Default value
    'defaultWeekStart'      => 'MO',  // Default value
    'skipRecurrence'        => false, // Default value
    'useTimeZoneWithRRules' => false, // Default value
));

var_dump($ical->events());

?>

You can see the full output of this script, below.

array(1) {
  [0]=>
  object(ICal\EventObject)#4 (24) {
    ["summary"]=>
    string(10) "Day S John"
    ["dtstart"]=>
    string(16) "20170301T123000Z"
    ["dtend"]=>
    string(16) "20170301T203000Z"
    ["duration"]=>
    NULL
    ["dtstamp"]=>
    string(16) "20170413T223147Z"
    ["uid"]=>
    string(32) "PRODUCTIONORG462SS208@domain.com"
    ["created"]=>
    NULL
    ["lastmodified"]=>
    NULL
    ["description"]=>
    string(24) "Group: University of XYZ"
    ["location"]=>
    NULL
    ["sequence"]=>
    string(1) "2"
    ["status"]=>
    NULL
    ["transp"]=>
    NULL
    ["organizer"]=>
    NULL
    ["attendee"]=>
    NULL
    ["uid_array"]=>
    array(2) {
      [0]=>
      array(0) {
      }
      [1]=>
      string(32) "PRODUCTIONORG462SS208@domain.com"
    }
    ["sequence_array"]=>
    array(2) {
      [0]=>
      array(0) {
      }
      [1]=>
      string(1) "2"
    }
    ["dtstamp_array"]=>
    array(2) {
      [0]=>
      array(0) {
      }
      [1]=>
      string(16) "20170413T223147Z"
    }
    ["dtstart_array"]=>
    array(3) {
      [0]=>
      array(0) {
      }
      [1]=>
      string(16) "20170301T123000Z"
      [2]=>
      int(1488371400)
    }
    ["dtend_array"]=>
    array(3) {
      [0]=>
      array(0) {
      }
      [1]=>
      string(16) "20170301T203000Z"
      [2]=>
      int(1488400200)
    }
    ["summary_array"]=>
    array(2) {
      [0]=>
      array(0) {
      }
      [1]=>
      string(10) "Day S John"
    }
    ["description_array"]=>
    array(2) {
      [0]=>
      array(0) {
      }
      [1]=>
      string(26) "Group: University of XYZ\n"
    }
    ["dtstart_tz"]=>
    string(15) "20170301T063000"
    ["dtend_tz"]=>
    string(15) "20170301T143000"
  }
}

@u01jmg3
Copy link
Owner

u01jmg3 commented Apr 19, 2017

Might be best to upload your *.ics file in this issue as the problem could be line endings

@dxdc
Copy link
Contributor Author

dxdc commented Apr 19, 2017

@u01jmg3 I can't upload to github for some reason, but you can download the sample project here.

https://www.dropbox.com/s/qwcu7an9zy0tmfn/demo.zip?dl=1

@u01jmg3
Copy link
Owner

u01jmg3 commented Apr 19, 2017

  • Sigh - your code works perfectly for me.
  • It must therefore be something to do with your setup.
  • I recently made this commit to support line endings on Macs.
  • Without having access to your setup to reproduce the issue I have no way of solving this.

demo

@dxdc
Copy link
Contributor Author

dxdc commented Apr 19, 2017

@u01jmg3 Well, at least we've isolated the issue :) which version of PHP are you using? Can you also provide your PHP.ini?

@dxdc
Copy link
Contributor Author

dxdc commented Apr 19, 2017

Btw. the ini_set function in your commit 07e775f#diff-50681920b8994c51dcfbb9a44850348fR171 had no effect for me. I can easily reproduce this issue on Linux and Mac.

@u01jmg3
Copy link
Owner

u01jmg3 commented Apr 19, 2017

  • Do you have access to a Windows machine to rule that out?
  • 5.6.19
  • php.ini
  • Perhaps the ini_set is having no effect and therefore you are seeing the issue you are seeing

@u01jmg3
Copy link
Owner

u01jmg3 commented Apr 19, 2017

Are you able to debug and try removing the \n in your iCal to see if you can get the other lines through the parser?

@dxdc
Copy link
Contributor Author

dxdc commented Apr 19, 2017

@u01jmg3 I tried removing \n (and even the leading space), no effect unfortunately. I also tried setting ini_set('auto_detect_line_endings', true); again manually. Neither changed the parsed result.

@u01jmg3
Copy link
Owner

u01jmg3 commented Apr 19, 2017

Try changing the EventObject constructor to just var_dump($data) to see what you get out

@dxdc
Copy link
Contributor Author

dxdc commented Apr 19, 2017

Just tried with vanilla PHP5 and PHP7 installs on Linux. No change.

If I add var_dump($data) to the EventObject constructor (I couldn't just eliminate the existing function, it produced NULL response), the only difference in behavior I see is the addition of \n at the end of the DESCRIPTION field.

E,g,
"Group: University of XYZ\n" (with this change) vs. "Group: University of XYZ" (original). I think there must be other line handling issues elsewhere in the code?

@dxdc
Copy link
Contributor Author

dxdc commented Apr 19, 2017

I found the issue and submitted a PR for you.

@u01jmg3
Copy link
Owner

u01jmg3 commented Apr 19, 2017

Try adding var_dump($lines) to the ICal constructor to see what PHP returns when it reads your iCal file

@u01jmg3 u01jmg3 added this to the v2.x.x milestone Apr 19, 2017
@u01jmg3 u01jmg3 removed their assignment Apr 19, 2017
@u01jmg3 u01jmg3 changed the title Support longer description field Support Mac/Linux line endings when unfolding Apr 19, 2017
@u01jmg3 u01jmg3 changed the title Support Mac/Linux line endings when unfolding Support Mac/Linux line endings when unfolding lines Apr 19, 2017
@dxdc
Copy link
Contributor Author

dxdc commented Apr 19, 2017

I think the best way to deal with this is to directly manipulate the $lines array and skip the whole implode/explode part.

We can find array elements that have tab or space as their first character and merge with the previous array. This would allow us to use the built-in spec for auto_detect_line_endings.

@u01jmg3
Copy link
Owner

u01jmg3 commented Apr 19, 2017

Feel free to pull together another PR - currently I only have time to fix bugs rather than explore developing enhancements. I can help where necessary though.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants