Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
fix small html_unescape bug in Mojo::Util
  • Loading branch information
kraih committed Dec 23, 2015
1 parent 2a04daa commit 50d884c
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 5 deletions.
3 changes: 2 additions & 1 deletion Changes
@@ -1,5 +1,6 @@

6.39 2015-12-21
6.39 2015-12-23
- Fixed small html_unescape bug in Mojo::Util.

6.38 2015-12-19
- Updated prettify.js to version 8-Dec-2015.
Expand Down
3 changes: 2 additions & 1 deletion lib/Mojo/Util.pm
Expand Up @@ -114,7 +114,8 @@ sub hmac_sha1_sum { hmac_sha1_hex @_ }

sub html_unescape {
my $str = shift;
$str =~ s/&(?:\#((?:\d{1,7}|x[0-9a-fA-F]{1,6}));|(\w+;))/_decode($1, $2)/ge;
$str
=~ s/&(?:\#((?:[0-9]{1,7}|x[0-9a-fA-F]{1,6}));|(\w+;))/_decode($1, $2)/ge;
return $str;
}

Expand Down
10 changes: 7 additions & 3 deletions t/mojo/util.t
Expand Up @@ -172,7 +172,7 @@ is url_escape('&business;23', 's&'), '%26bu%73ine%73%73;23',
'right URL escaped result';

# url_escape (nothing to escape)
is url_escape('foobar123-._~'), 'foobar123-._~', 'right URL escaped result';
is url_escape('foobar123-._~'), 'foobar123-._~', 'no changes';

# url_unescape
is url_unescape('business%3B23'), 'business;23', 'right URL unescaped result';
Expand Down Expand Up @@ -202,7 +202,11 @@ is html_unescape('foobar&apos;&lt;baz&gt;&#x26;&#34;'), "foobar'<baz>&\"",
'right HTML unescaped result';

# html_unescape (nothing to unescape)
is html_unescape('foobar'), 'foobar', 'right HTML unescaped result';
is html_unescape('foobar'), 'foobar', 'no changes';

# url_unescape (bengal numbers with nothing to unescape)
is html_unescape('&#০৩৯;&#x০৩৯;'), '&#০৩৯;&#x০৩৯;',
'no changes';

# html_unescape (UTF-8)
is html_unescape(decode 'UTF-8', 'foo&lt;baz&gt;&#x26;&#34;&OElig;&Foo;'),
Expand All @@ -214,7 +218,7 @@ is xml_escape(qq{la<f>\nbar"baz"'yada\n'&lt;la}),
'right XML escaped result';

# xml_escape (UTF-8 with nothing to escape)
is xml_escape('привет'), 'привет', 'right XML escaped result';
is xml_escape('привет'), 'привет', 'no changes';

# xml_escape (UTF-8)
is xml_escape('привет<foo>'), 'привет&lt;foo&gt;',
Expand Down

0 comments on commit 50d884c

Please sign in to comment.