Skip to content

Commit

Permalink
[+]: need some testing with php 5.3 -> ping to travis ci
Browse files Browse the repository at this point in the history
  • Loading branch information
Lars Moelleken committed Aug 12, 2015
1 parent 9da4960 commit 2b5fa3a
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 8 deletions.
10 changes: 6 additions & 4 deletions src/voku/helper/UTF8.php
Original file line number Diff line number Diff line change
Expand Up @@ -1450,9 +1450,7 @@ public static function strcspn($str, $charlist, $start = 0, $len = 2147483647)
$str = (string)$str;
}

return preg_match('/^(.*?)' . self::rxClass($charlist) . '/us', $str, $len) ? self::strlen($len[1]) : self::strlen(
$str
);
return preg_match('/^(.*?)' . self::rxClass($charlist) . '/us', $str, $len) ? self::strlen($len[1]) : self::strlen($str);
}

/**
Expand Down Expand Up @@ -1721,7 +1719,11 @@ public static function html_entity_decode($string, $flags = null, $encoding = 'U
}

if ($flags === null) {
$flags = Bootup::is_php('5.4') ? ENT_COMPAT | ENT_HTML5 : ENT_COMPAT;
if (Bootup::is_php('5.4') === true) {
$flags = ENT_COMPAT | ENT_HTML5;
} else {
$flags = ENT_COMPAT;
}
}

do {
Expand Down
45 changes: 41 additions & 4 deletions tests/UTF8Test.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<?php

use voku\helper\Bootup;
use voku\helper\UTF8;

/**
Expand Down Expand Up @@ -333,8 +334,9 @@ public function testHtmlEntityDecode()
'Who&#039;s Online' => 'Who&#039;s Online',
'Who&amp;#039;s Online' => 'Who&#039;s Online',
'Who&amp;amp;#039;s Online' => 'Who&#039;s Online',
'who\'s online' => 'who\'s online',
'Who\'s Online' => 'Who\'s Online',
'who\'s online&colon;' => 'who\'s online&colon;',
"Who\'s Online&#x0003A;" => 'Who\\\'s Online:',
"&lt;&copy; W3S&ccedil;h&deg;&deg;&brvbar;&sect;&gt;" => "<© W3Sçh°°¦§>",
);

// WARNING: HipHop error // "ENT_COMPAT" isn't working
Expand Down Expand Up @@ -365,15 +367,48 @@ public function testHtmlEntityDecodeWithEntQuotes()
'Who&#039;s Online' => 'Who\'s Online',
'Who&amp;#039;s Online' => 'Who\'s Online',
'Who&amp;amp;#039;s Online' => 'Who\'s Online',
'who\'s online' => 'who\'s online',
'Who\'s Online' => 'Who\'s Online',
'who\'s online&colon;' => 'who\'s online&colon;',
"Who\'s Online&#x0003A;" => 'Who\\\'s Online:',
"&lt;&copy; W3S&ccedil;h&deg;&deg;&brvbar;&sect;&gt;" => "<© W3Sçh°°¦§>",
);

foreach ($testArray as $before => $after) {
self::assertEquals($after, UTF8::html_entity_decode($before, ENT_QUOTES, 'UTF-8'), 'error by ' . $before);
}
}

public function testHtmlEntityDecodeWithHtml5()
{
$testArray = array(
'κόσμε' => 'κόσμε',
'Κόσμε' => 'Κόσμε',
'öäü-κόσμεκόσμε-äöü' => 'öäü-κόσμεκόσμε-äöü',
'öäü-κόσμεκόσμε-äöüöäü-κόσμεκόσμε-äöü' => 'öäü-κόσμεκόσμε-äöüöäü-κόσμεκόσμε-äöü',
'äöüäöüäöü-κόσμεκόσμεäöüäöüäöü-κόσμεκόσμεäöüäöüäöü-κόσμεκόσμε' => 'äöüäöüäöü-κόσμεκόσμεäöüäöüäöü-κόσμεκόσμεäöüäöüäöü-κόσμεκόσμε',
'äöüäöüäöü-κόσμεκόσμεäöüäöüäöü-Κόσμεκόσμεäöüäöüäöü-κόσμεκόσμεäöüäöüäöü-κόσμεκόσμε' => 'äöüäöüäöü-κόσμεκόσμεäöüäöüäöü-Κόσμεκόσμεäöüäöüäöü-κόσμεκόσμεäöüäöüäöü-κόσμεκόσμε',
' ' => ' ',
'' => '',
'&lt;abcd&gt;\'$1\'(&quot;&amp;2&quot;)' => '<abcd>\'$1\'("&2")',
'&lt;script&gt;alert(&quot;foo&quot;);&lt;/script&gt;, &lt;marquee&gt;test&lt;/marquee&gt;' => '<script>alert("foo");</script>, <marquee>test</marquee>',
'&amp;lt;script&amp;gt;alert(&amp;quot;XSS&amp;quot;)&amp;lt;/script&amp;gt;' => '<script>alert("XSS")</script>',
'who&#039;s online' => 'who\'s online',
'who&amp;#039;s online' => 'who\'s online',
'who&#039;s online-' => 'who\'s online-',
'Who&#039;s Online' => 'Who\'s Online',
'Who&amp;#039;s Online' => 'Who\'s Online',
'Who&amp;amp;#039;s Online' => 'Who\'s Online',
'who\'s online&colon;' => 'who\'s online:',
"Who\'s Online&#x0003A;" => 'Who\\\'s Online:',
"&lt;&copy; W3S&ccedil;h&deg;&deg;&brvbar;&sect;&gt;" => "<© W3Sçh°°¦§>",
);

if (Bootup::is_php('5.4') === true) {
foreach ($testArray as $before => $after) {
self::assertEquals($after, UTF8::html_entity_decode($before, ENT_QUOTES | ENT_HTML5, 'UTF-8'), 'error by ' . $before);
}
}
}

public function testRemoveInvisibleCharacters()
{
$testArray = array(
Expand Down Expand Up @@ -587,6 +622,7 @@ public function testUtf8DecodeUtf8Encode()
" - ÖÄÜ- " => " - ÖÄÜ- ",
"öäü" => "öäü",
"" => "",
"foobar" => "foobar",
);

foreach ($tests as $before => $after) {
Expand All @@ -601,6 +637,7 @@ public function testUtf8EncodeUtf8Decode()
" - ÖÄÜ- " => " - ÖÄÜ- ",
"öäü" => "öäü",
"" => "",
"foobar" => "foobar",
);

foreach ($tests as $before => $after) {
Expand Down

0 comments on commit 2b5fa3a

Please sign in to comment.