Skip to content

Commit

Permalink
fixed xml_escape to use character semantics
Browse files Browse the repository at this point in the history
  • Loading branch information
kraih committed Oct 13, 2009
1 parent 0c5bee6 commit 046b445
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 1 deletion.
1 change: 1 addition & 0 deletions Changes
Expand Up @@ -12,6 +12,7 @@ This file documents the revision history for Perl extension Mojo.
defensive and made them in turn 20 times faster.
- Fixed keep alive problem in Mojo::Transaction::Pipeline.
- Fixed and simplified Mojo::Parameters. (gbarr)
- Fixed xml_escape to use character semantics. (vti)
- Fixed body helper in Mojo::Message and added tests. (vti)
- Fixed padding byte handling in Mojo::Server::FastCGI.
(Jaroslav Muhin)
Expand Down
3 changes: 3 additions & 0 deletions lib/Mojo/ByteStream.pm
Expand Up @@ -503,6 +503,9 @@ sub url_unescape {
sub xml_escape {
my $self = shift;

# Character semantics
no bytes;

# Replace "&", "<", ">", """ and "'"
for ($self->{bytestream}) {
s/&/&amp;/g;
Expand Down
12 changes: 11 additions & 1 deletion t/mojo/bytestream.t
Expand Up @@ -5,10 +5,12 @@
use strict;
use warnings;

use utf8;

# Homer, we're going to ask you a few simple yes or no questions.
# Do you understand?
# Yes. *lie dectector blows up*
use Test::More tests => 30;
use Test::More tests => 32;

use_ok('Mojo::ByteStream', 'b');

Expand Down Expand Up @@ -121,3 +123,11 @@ is("$stream", '/usr/local/lib/perl5/site_perl/5.10.0/Mojo/ByteStream.pm');
# xml_escape
$stream = b(qq/la<f>\nbar"baz"'yada\n'&lt;la/)->xml_escape;
is("$stream", "la&lt;f&gt;\nbar&quot;baz&quot;&apos;yada\n&apos;&amp;lt;la");

# utf8 xml_escape with nothing to escape
$stream = b(qq/привет/)->xml_escape;
is("$stream", "привет");

# utf8 xml_escape
$stream = b(qq/привет<foo>/)->xml_escape;
is("$stream", "привет&lt;foo&gt;");

0 comments on commit 046b445

Please sign in to comment.