From f78e068a77122a0c53cd1ae281ca7efcbe92d30d Mon Sep 17 00:00:00 2001 From: Andrew McMillan Date: Thu, 26 Sep 2013 15:53:40 +0200 Subject: [PATCH] Fix a bunch of bugs discovered through RRULE expansion issues. --- inc/vComponent.php | 37 +++++++++++++++++++++++++++++-------- inc/vObject.php | 10 +++------- 2 files changed, 32 insertions(+), 15 deletions(-) diff --git a/inc/vComponent.php b/inc/vComponent.php index a9be2b0..4da9dee 100644 --- a/inc/vComponent.php +++ b/inc/vComponent.php @@ -1,4 +1,18 @@ + * @copyright Morphoss Ltd + * @license http://gnu.org/copyleft/lgpl.html GNU LGPL v2 or later + * + */ include_once('vObject.php'); //include_once('HeapLines.php'); @@ -18,6 +32,7 @@ const KEYBEGINLENGTH = 6; const KEYEND = "END:"; const KEYENDLENGTH = 4; + const VEOL = "\r\n"; public static $PREPARSED = false; @@ -558,7 +573,7 @@ } - if ( $type != null && isset($this->components)) { + if ( $type != null && !empty($this->components)) { $testtypes = (gettype($type) == 'string' ? array( $type => true ) : $type ); // First remove all the existing ones of that type foreach( $this->components AS $k => $v ) { @@ -573,11 +588,10 @@ } } else { + $this->components = array(); if ( $this->isValid()) { $this->invalidate(); } - unset($this->components); - } return $this->isValid(); @@ -594,6 +608,10 @@ if ( $this->isValid()) { $this->invalidate(); } + if ( empty($type) ) { + $this->components = $new_component; + return; + } $this->ClearComponents($type); foreach( $new_component AS $k => $v ) { @@ -695,7 +713,10 @@ $strs = preg_split( "/\r?\n/", $content ); $wrapped = ""; foreach ($strs as $str) { - $wrapped .= preg_replace( '/(.{72})/u', '$1'."\r\n ", $str ) ."\r\n"; +// print "Before: >>$str<<, len(".strlen($str).")\n"; + $wrapped_bit = (strlen($str) == 72 ? $str : preg_replace( '/(.{72})/u', '$1'."\r\n ", $str )) .self::VEOL; +// print "After: >>$wrapped_bit<<\n"; + $wrapped .= $wrapped_bit; } return $wrapped; } @@ -718,7 +739,7 @@ */ protected function RenderWithoutWrap($restricted_properties = null, $force_rendering = false){ $unrolledComponents = isset($this->components); - $rendered = vComponent::KEYBEGIN . $this->type . "\r\n"; + $rendered = vComponent::KEYBEGIN . $this->type . self::VEOL; if($this->isValid()){ @@ -734,7 +755,7 @@ //$count++; $component_render = $component->RenderWithoutWrap(); if(strlen($component_render) > 0){ - $rendered .= $component_render . "\r\n"; + $rendered .= $component_render . self::VEOL; } //$component->close(); @@ -754,7 +775,7 @@ if(isset($this->properties)){ foreach( $this->properties AS $k => $v ) { if ( method_exists($v, 'Render') ) { - $forebug = $v->Render() . "\r\n"; + $forebug = $v->Render() . self::VEOL; $rendered .= $forebug; } } @@ -780,7 +801,7 @@ $iterator = $this->iterator; $inInnerObject = 0; do { - $line = $iterator->current() . "\r\n"; + $line = $iterator->current() . self::VEOL; $seek = $iterator->key(); $posStart = strpos($line, vComponent::KEYBEGIN); diff --git a/inc/vObject.php b/inc/vObject.php index b2487d6..d0984d1 100644 --- a/inc/vObject.php +++ b/inc/vObject.php @@ -20,16 +20,12 @@ abstract class vObject { function isValid(){ - return isset($this->master) ? $this->master->valid : $this->valid; + return $this->valid; } protected function invalidate(){ - if(isset($this->master)){ - $this->master->valid = false; - } else { - $this->valid = false; - } - + if ( isset($this->master) && $this->master != $this ) $this->master->invalidate(); + $this->valid = false; } function setMaster($master){ -- 2.11.4.GIT