Skip to content
This repository has been archived by the owner on Jan 29, 2020. It is now read-only.

Commit

Permalink
Merge branch 'cs/various-things' of https://github.com/Maks3w/zf2
Browse files Browse the repository at this point in the history
  • Loading branch information
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 26 deletions.
40 changes: 20 additions & 20 deletions src/Escaper.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class Escaper
/**
* Current encoding for escaping. If not UTF-8, we convert strings from this encoding
* pre-escaping and back to this encoding post-escaping.
*
*
* @var string
*/
protected $encoding = 'utf-8';
Expand All @@ -33,35 +33,35 @@ class Escaper
* htmlspecialchars(). We modify these for PHP 5.4 to take advantage
* of the new ENT_SUBSTITUTE flag for correctly dealing with invalid
* UTF-8 sequences.
*
*
* @var string
*/
protected $htmlSpecialCharsFlags = ENT_QUOTES;

/**
* Static Matcher which escapes characters for HTML Attribute contexts
*
*
* @var Closure
*/
protected $htmlAttrMatcher = null;

/**
* Static Matcher which escapes characters for Javascript contexts
*
*
* @var Closure
*/
protected $jsMatcher = null;

/**
* Static Matcher which escapes characters for CSS Attribute contexts
*
*
* @var Closure
*/
protected $cssMatcher = null;

/**
* List of all encoding supported by this class
*
*
* @var array
*/
protected $supportedEncodings = array(
Expand All @@ -80,7 +80,7 @@ class Escaper
* Constructor: Single parameter allows setting of global encoding for use by
* the current object. If PHP 5.4 is detected, additional ENT_SUBSTITUTE flag
* is set for htmlspecialchars() calls.
*
*
* @param string $encoding
*/
public function __construct($encoding = null)
Expand All @@ -107,7 +107,7 @@ public function __construct($encoding = null)

/**
* Return the encoding that all output/input is expected to be encoded in.
*
*
* @return string
*/
public function getEncoding()
Expand All @@ -118,7 +118,7 @@ public function getEncoding()
/**
* Escape a string for the HTML Body context where there are very few characters
* of special meaning. Internally this will use htmlspecialchars().
*
*
* @param string $string
* @return string
*/
Expand All @@ -132,7 +132,7 @@ public function escapeHtml($string)
* Escape a string for the HTML Attribute context. We use an extended set of characters
* to escape that are not covered by htmlspecialchars() to cover cases where an attribute
* might be unquoted or quoted illegally (e.g. backticks are valid quotes for IE).
*
*
* @param string $string
* @return string
*/
Expand All @@ -158,7 +158,7 @@ public function escapeHtmlAttr($string)
* of cases where HTML escaping was not applied on top of Javascript escaping correctly.
* Backslash escaping is not used as it still leaves the escaped character as-is and so
* is not useful in a HTML context.
*
*
* @param string $string
* @return string
*/
Expand All @@ -180,7 +180,7 @@ public function escapeJs($string)
* Escape a string for the URI or Parameter contexts. This should not be used to escape
* an entire URI - only a subcomponent being inserted. The function is a simple proxy
* to rawurlencode() which now implements RFC 3986 since PHP 5.3 completely.
*
*
* @param string $string
* @return string
*/
Expand All @@ -192,7 +192,7 @@ public function escapeUrl($string)
/**
* Escape a string for the CSS context. CSS escaping can be applied to any string being
* inserted into CSS and escapes everything except alphanumerics.
*
*
* @param string $string
* @return string
*/
Expand All @@ -213,7 +213,7 @@ public function escapeCss($string)
/**
* Callback function for preg_replace_callback that applies HTML Attribute
* escaping to all matches.
*
*
* @param array $matches
* @return string
*/
Expand Down Expand Up @@ -253,7 +253,7 @@ public function htmlAttrMatcher($matches)
/**
* Callback function for preg_replace_callback that applies Javascript
* escaping to all matches.
*
*
* @param array $matches
* @return string
*/
Expand All @@ -271,7 +271,7 @@ public function jsMatcher($matches)
/**
* Callback function for preg_replace_callback that applies CSS
* escaping to all matches.
*
*
* @param array $matches
* @return string
*/
Expand All @@ -291,7 +291,7 @@ public function cssMatcher($matches)
/**
* Converts a string to UTF-8 from the base encoding. The base encoding is set via this
* class' constructor.
*
*
* @param string $string
* @return string
*/
Expand Down Expand Up @@ -326,7 +326,7 @@ protected function fromUtf8($string)

/**
* Checks if a given string appears to be valid UTF-8 or not.
*
*
* @param string $string
* @return bool
*/
Expand All @@ -343,7 +343,7 @@ protected function isUtf8($string)
/**
* Encoding conversion helper which wraps iconv and mbstring where they exist or throws
* and exception where neither is available.
*
*
* @param string $string
* @return string
*/
Expand Down Expand Up @@ -375,7 +375,7 @@ protected function convertEncoding($string, $to, $from)
* has become HTML5's XML Serialisation which is restricted to the those named
* entities that XML supports. Using HTML entities would result in this error:
* XML Parsing Error: undefined entity
*
*
* @var array
*/
protected $htmlNamedEntityMap = array(
Expand Down
12 changes: 6 additions & 6 deletions test/EscaperTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ class EscaperTest extends \PHPUnit_Framework_TestCase
/* Encode spaces for quoteless attribute protection */
' ' => '\\20 ',
);


public function setUp()
{
Expand Down Expand Up @@ -263,7 +263,7 @@ public function testUrlEscapingConvertsSpecialChars()
* Range tests to confirm escaped range of characters is within OWASP recommendation
*/

/**
/**
* Only testing the first few 2 ranges on this prot. function as that's all these
* other range tests require
*/
Expand All @@ -280,7 +280,7 @@ public function testUnicodeCodepointConversionToUtf8()

/**
* Convert a Unicode Codepoint to a literal UTF-8 character.
*
*
* @param int Unicode codepoint in hex notation
* @return string UTF-8 literal string
*/
Expand Down Expand Up @@ -310,7 +310,7 @@ protected function codepointToUtf8($codepoint)
public function testJavascriptEscapingEscapesOwaspRecommendedRanges()
{
$immune = array(',', '.', '_'); // Exceptions to escaping ranges
for ($chr=0; $chr < 0xFF; $chr++) {
for ($chr=0; $chr < 0xFF; $chr++) {
if ($chr >= 0x30 && $chr <= 0x39
|| $chr >= 0x41 && $chr <= 0x5A
|| $chr >= 0x61 && $chr <= 0x7A) {
Expand All @@ -333,7 +333,7 @@ public function testJavascriptEscapingEscapesOwaspRecommendedRanges()
public function testHtmlAttributeEscapingEscapesOwaspRecommendedRanges()
{
$immune = array(',', '.', '-', '_'); // Exceptions to escaping ranges
for ($chr=0; $chr < 0xFF; $chr++) {
for ($chr=0; $chr < 0xFF; $chr++) {
if ($chr >= 0x30 && $chr <= 0x39
|| $chr >= 0x41 && $chr <= 0x5A
|| $chr >= 0x61 && $chr <= 0x7A) {
Expand All @@ -356,7 +356,7 @@ public function testHtmlAttributeEscapingEscapesOwaspRecommendedRanges()
public function testCssEscapingEscapesOwaspRecommendedRanges()
{
$immune = array(); // CSS has no exceptions to escaping ranges
for ($chr=0; $chr < 0xFF; $chr++) {
for ($chr=0; $chr < 0xFF; $chr++) {
if ($chr >= 0x30 && $chr <= 0x39
|| $chr >= 0x41 && $chr <= 0x5A
|| $chr >= 0x61 && $chr <= 0x7A) {
Expand Down

0 comments on commit e2e3049

Please sign in to comment.