From 97b4d7ca7f7edcedc2d9c113a60d827a967f2c5e Mon Sep 17 00:00:00 2001 From: xue <> Date: Sat, 27 Jan 2007 23:08:33 +0000 Subject: Fixed the bug that TXmlElement did not encode attribute and text values when being saved as a string --- framework/Xml/TXmlDocument.php | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) (limited to 'framework/Xml') diff --git a/framework/Xml/TXmlDocument.php b/framework/Xml/TXmlDocument.php index cc5b40f9..b4293763 100644 --- a/framework/Xml/TXmlDocument.php +++ b/framework/Xml/TXmlDocument.php @@ -200,7 +200,10 @@ class TXmlElement extends TComponent if($this->_attributes!==null) { foreach($this->_attributes as $name=>$value) + { + $value=$this->xmlEncode($value); $attr.=" $name=\"$value\""; + } } $prefix=str_repeat(' ',$indent*4); if($this->getHasElement()) @@ -211,13 +214,26 @@ class TXmlElement extends TComponent $str.=$prefix."_tagName}>"; return $str; } - else if($this->getValue()!=='') + else if(($value=$this->getValue())!=='') { - return $prefix."<{$this->_tagName}$attr>{$this->_value}_tagName}>"; + $value=$this->xmlEncode($value); + return $prefix."<{$this->_tagName}$attr>$value_tagName}>"; } else return $prefix."<{$this->_tagName}$attr />"; } + + private function xmlEncode($str) + { + return strtr($str,array( + '>'=>'>', + '<'=>'<', + '&'=>'&', + '"'=>'"', + "\r"=>' ', + "\t"=>' ', + "\n"=>' ')); + } } /** -- cgit v1.2.3