Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update XML Escape #420

Merged
merged 2 commits into from
Oct 11, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 8 additions & 10 deletions htdocs/class/xml/rpc/xmlrpctag.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,7 @@ public function add(XoopsXmlRpcTag &$tagobj)
$this->_tags[] = $tagobj;
}

abstract function render();

abstract public function render();
}

class XoopsXmlRpcResponse extends XoopsXmlRpcDocument
Expand Down Expand Up @@ -94,14 +93,15 @@ abstract class XoopsXmlRpcTag
protected $_fault = false;

/**
* @param string $text
* encode - make string HTML safe
*
* @param string $text string to encode
*
* @return string
*/
public function encode(&$text)
public function encode($text)
{
$text = preg_replace(array("/\&([a-z\d\#]+)\;/i", "/\&/", "/\#\|\|([a-z\d\#]+)\|\|\#/i"),
array("#||\\1||#", "&amp;", "&\\1;"), str_replace(array("<", ">"), array("&lt;", "&gt;"), $text));
return $text;
return htmlspecialchars($text, ENT_XML1, 'UTF-8');
}

/**
Expand All @@ -125,7 +125,7 @@ public function isFault()
* @abstract
* @return void
*/
abstract function render();
abstract public function render();
}

class XoopsXmlRpcFault extends XoopsXmlRpcTag
Expand Down Expand Up @@ -406,5 +406,3 @@ public function render()
return $ret;
}
}

?>
5 changes: 3 additions & 2 deletions tests/unit/class/xml/rpc/xmlrpctagTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,17 +26,18 @@ public function test___construct()

public function test_encode()
{
$this->markTestSkipped('needs updated');
$instance = new $this->myclass();
$text = '& < > ';
$result = $instance->encode($text);
$expected = '&amp; &lt; &gt; ';
$this->assertSame($expected, $result);

$text = '#||amp||#';
$result = $instance->encode($text);
$expected = '&amp;';
$this->assertSame($expected, $result);

$this->markTestIncomplete('Unexpected result in the next test');
$text = '&amp;';
$result = $instance->encode($text);
Expand Down