Skip to content

Commit

Permalink
Add simpler string replacement
Browse files Browse the repository at this point in the history
  • Loading branch information
colinodell committed Nov 10, 2014
1 parent e059632 commit cacf3d0
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ This changelog references the changes contained in each release.

* Removed "is" prefix from boolean methods
* Updated to latest version of PHPUnit
* Added simpler string replacement to a method

* **0.2.0**

Expand Down
10 changes: 6 additions & 4 deletions src/HtmlRenderer.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,14 @@ protected function escape($string, $preserveEntities = false)
if ($preserveEntities) {
$string = preg_replace('/[&](?![#](x[a-f0-9]{1,8}|[0-9]{1,8});|[a-z][a-z0-9]{1,31};)/i', '&', $string);
} else {
$string = preg_replace('/[&]/', '&', $string);
$string = str_replace('&', '&', $string);
}

$string = preg_replace('/[<]/', '&lt;', $string);
$string = preg_replace('/[>]/', '&gt;', $string);
$string = preg_replace('/["]/', '&quot;', $string);
$string = strtr($string, array(
'<' => '&lt;',
'>' => '&gt;',
'"' => '&quot;'
));

return $string;
}
Expand Down

0 comments on commit cacf3d0

Please sign in to comment.