Skip to content
This repository has been archived by the owner on Jan 10, 2022. It is now read-only.

Commit

Permalink
Dont reset document when their is partial data
Browse files Browse the repository at this point in the history
  • Loading branch information
fabiang committed Nov 19, 2014
1 parent c59f050 commit 9032ee7
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 2 deletions.
1 change: 1 addition & 0 deletions src/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ public function __construct(Options $options, EventManagerInterface $eventManage
$connection = $options->getConnection();
} else {
$connection = Socket::factory($options);
$options->setConnection($connection);

This comment has been minimized.

Copy link
@n10ty

n10ty Nov 20, 2014

Contributor

Why set connection in "if", without doing it after? If condition will return "true" Connection in Options wouldn't be set.

This comment has been minimized.

Copy link
@fabiang

fabiang Nov 20, 2014

Author Owner

Sorry, but I don't get your point.

}
$this->options = $options;
$this->connection = $connection;
Expand Down
4 changes: 2 additions & 2 deletions src/Stream/XMLStream.php
Original file line number Diff line number Diff line change
Expand Up @@ -183,15 +183,15 @@ protected function clearDocument($source)
$documentElement = $this->document->documentElement;

// collect xml declaration
if ('<?xml' === substr($source, 0, 5) || null === $documentElement) {
if ('<?xml' === substr($source, 0, 5)) {
$this->reset();

$matches = array();
if (preg_match('/^<\?xml.*encoding=(\'|")([\w-]+)\1.*?>/i', $source, $matches)) {
$this->encoding = $matches[2];
xml_parser_set_option($this->parser, XML_OPTION_TARGET_ENCODING, $this->encoding);
}
} else {
} elseif (null !== $documentElement) {
// clean the document
/* @var $childNode \DOMNode */
while ($documentElement->hasChildNodes()) {
Expand Down
22 changes: 22 additions & 0 deletions tests/src/Stream/XMLStreamTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -352,4 +352,26 @@ public function testSetAndGetEventManager()
$this->assertSame($eventManager, $this->object->setEventManager($eventManager)->getEventManager());
}

/**
* @covers ::parse
* @uses Fabiang\Xmpp\Event\Event
* @uses Fabiang\Xmpp\Event\XMLEvent
* @uses Fabiang\Xmpp\Event\EventManager
* @uses Fabiang\Xmpp\Stream\XmlStream::__construct
* @uses Fabiang\Xmpp\Stream\XmlStream::clearDocument
* @uses Fabiang\Xmpp\Stream\XmlStream::startXml
* @uses Fabiang\Xmpp\Stream\XmlStream::endXml
* @uses Fabiang\Xmpp\Stream\XmlStream::createAttributeNodes
* @uses Fabiang\Xmpp\Stream\XmlStream::cacheEvent
* @uses Fabiang\Xmpp\Stream\XmlStream::trigger
* @uses Fabiang\Xmpp\Stream\XmlStream::reset
* @uses Fabiang\Xmpp\Stream\XmlStream::getEventManager
* @uses Fabiang\Xmpp\Stream\XmlStream::setEventManager
* @uses Fabiang\Xmpp\Stream\XmlStream::getEventObject
*/
public function testParseCutted()
{
$this->assertInstanceOf('DOMDocument', $this->object->parse('<'));
$this->assertInstanceOf('DOMDocument', $this->object->parse('features xmlns="test"></features>'));
}
}

0 comments on commit 9032ee7

Please sign in to comment.