Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
use a more efficient regex
  • Loading branch information
kraih committed Jan 17, 2015
1 parent acf0baa commit 782728f
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/Mojo/Util.pm
Expand Up @@ -301,7 +301,7 @@ sub tablify {

sub term_escape {
my $str = shift;
$str =~ s/([[:cntrl:]])/$1 eq "\n" ? $1 : sprintf '\\x%02x', ord $1/ge;
$str =~ s/([\x00-\x09\x0b-\x1f\x7f])/sprintf '\\x%02x', ord $1/ge;
return $str;
}

Expand Down
1 change: 1 addition & 0 deletions t/mojo/util.t
Expand Up @@ -457,5 +457,6 @@ is dumper([1, 2]), "[\n 1,\n 2\n]\n", 'right result';
# term_escape
is term_escape("Accept: */*\x0d\x0a"), "Accept: */*\\x0d\x0a", 'right result';
is term_escape("\t\b\r\n\f"), "\\x09\\x08\\x0d\n\\x0c", 'right result';
is term_escape("\x00\x09\x0b\x1f\x7f"), '\x00\x09\x0b\x1f\x7f', 'right result';

done_testing();

0 comments on commit 782728f

Please sign in to comment.