Skip to content

Commit

Permalink
bugfix: change regex to lazy quantifier in Serializer #patch (#18)
Browse files Browse the repository at this point in the history
* bugfix: change regex to lazy quantifier in Serializer #patch

* code review fix #patch

---------

Co-authored-by: Giovanni Piemontese <[email protected]>
  • Loading branch information
faaru-io and ynnoig authored Nov 9, 2023
1 parent 3d8449b commit f0bc027
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/CXml/Serializer.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public static function create(): self
public function deserialize(string $xml): CXml
{
// remove doctype (if exists), as it would throw a JMS\Serializer\Exception\InvalidArgumentException
$xml = \preg_replace('/<!doctype.+>/i', '', $xml);
$xml = \preg_replace('/<!doctype[^>]+?>/i', '', $xml);

if (empty($xml)) {
throw new \RuntimeException('Cannot deserialize empty string');
Expand Down
14 changes: 13 additions & 1 deletion tests/CXmlTest/Model/SerializerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -377,6 +377,18 @@ public function testSerializeDateOnly(): void
</Request>
</cXML>';

$this->assertXmlStringEqualsXmlString($expectedXml, $actualXml);
$this->assertXmlStringEqualsXmlString($expectedXml, $actualXml);
}

public function testDeserializeOneRowXml(): void
{
$xml = '<?xml version="1.0" encoding="UTF-8"?><!DOCTYPE cXML SYSTEM "http://xml.cxml.org/schemas/cXML/1.1.008/cXML.dtd"><cXML timestamp="2022-06-07T10:09:56+00:00" payloadID="x.y.z"><Response><Status code="200" text="OK">Ping Response CXml</Status></Response></cXML>';

$serializer = Serializer::create();
$cXml = $serializer->deserialize($xml);

$resultingXml = $serializer->serialize($cXml);

$this->assertXmlStringEqualsXmlString($xml, $resultingXml);
}
}

0 comments on commit f0bc027

Please sign in to comment.