merged branch sprain/sprain/xml-encoder-cdata (PR #3134)
Commits -------9cb513f
Now… no more tabs!7f34643
[Pull Request 3134] Improved code based on comments90abc0f
[Serializer][XmlEncoder] add CDATA padding only if necessary Discussion ---------- [Serializer][XmlEncoder] add CDATA padding only if necessary Changed XML encoder so CDATA padding is only added to value if necessary. --------------------------------------------------------------------------- by fabpot at 2012-01-17T21:34:59Z You should add some unit tests.
This commit is contained in:
commit
54e14e7b11
@ -323,6 +323,18 @@ class XmlEncoder extends SerializerAwareEncoder implements EncoderInterface, Dec
|
||||
return $appendNode;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if a value contains any characters which would require CDATA wrapping.
|
||||
*
|
||||
* @param string $val
|
||||
*
|
||||
* @return Boolean
|
||||
*/
|
||||
private function needsCdataWrapping($val)
|
||||
{
|
||||
return preg_match('/[<>&]/', $val);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests the value being passed and decide what sort of element to create
|
||||
*
|
||||
@ -344,8 +356,10 @@ class XmlEncoder extends SerializerAwareEncoder implements EncoderInterface, Dec
|
||||
return $this->buildXml($node, $this->serializer->normalize($val, $this->format));
|
||||
} elseif (is_numeric($val)) {
|
||||
return $this->appendText($node, (string) $val);
|
||||
} elseif (is_string($val)) {
|
||||
} elseif (is_string($val) && $this->needsCdataWrapping($val)) {
|
||||
return $this->appendCData($node, $val);
|
||||
} elseif (is_string($val)) {
|
||||
return $this->appendText($node, $val);
|
||||
} elseif (is_bool($val)) {
|
||||
return $this->appendText($node, (int) $val);
|
||||
} elseif ($val instanceof \DOMNode) {
|
||||
|
Reference in New Issue
Block a user