Skip to content

Commit

Permalink
OPTIONS might be an empty tag.
Browse files Browse the repository at this point in the history
Note: Tested with typical OPTIONS tags, but I have no clients that send
empty OPTIONS. Need to write a proper unit test for the code in the decoder.
  • Loading branch information
mrubinsk committed Jan 28, 2014
1 parent 2368200 commit afe5fc6
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 1 deletion.
4 changes: 3 additions & 1 deletion framework/ActiveSync/lib/Horde/ActiveSync/Request/Sync.php
Expand Up @@ -793,7 +793,9 @@ protected function _parseSyncFolders()
break;

case Horde_ActiveSync::SYNC_OPTIONS:
$this->_parseSyncOptions($collection);
if (!$this->_decoder->isEmptyElement($this->_decoder->getLastStartElement())) {
$this->_parseSyncOptions($collection);
}
break;

case Horde_ActiveSync::SYNC_COMMANDS:
Expand Down
39 changes: 39 additions & 0 deletions framework/ActiveSync/lib/Horde/ActiveSync/Wbxml/Decoder.php
Expand Up @@ -69,6 +69,14 @@ class Horde_ActiveSync_Wbxml_Decoder extends Horde_ActiveSync_Wbxml
protected $_ungetbuffer;
protected $_readHeader = false;

/**
* Cache the last successfully fetched start tag array. Used to be able
* to easily detected emtpy nodes after the element was already fetched.
*
* @var array
*/
protected $_lastStartElement;

/**
* Start reading the wbxml stream, pulling off the initial header and
* populate the properties.
Expand Down Expand Up @@ -159,6 +167,35 @@ public function getElement()
return false;
}

/**
* Returns whether or not the passed in element array represents an
* empty tag.
*
* @param array $el The element array.
*
* @return boolean True if $el is an empty start tag, otherwise false.
*/
public function isEmptyElement(array $el)
{
switch ($el[self::EN_TYPE]) {
case self::EN_TYPE_STARTTAG:
return !($el[self::EN_FLAGS] & self::EN_FLAGS_CONTENT);
default:
// Not applicable.
return false;
}
}

/**
* Returns the last element array fetched using getElementStartTag()
*
* @return array|boolean The element array, or false if none available.
*/
public function getLastStartElement()
{
return $this->_lastStartElement;
}

/**
* Peek at the next element in the stream.
*
Expand Down Expand Up @@ -186,8 +223,10 @@ public function getElementStartTag($tag)
if ($element[self::EN_TYPE] == self::EN_TYPE_STARTTAG &&
$element[self::EN_TAG] == $tag) {

$this->_lastStartElement = $element;
return $element;
} else {
$this->_lastStartElement = false;
$this->_ungetElement($element);
}

Expand Down

0 comments on commit afe5fc6

Please sign in to comment.