Skip to content

Commit f636f4b

Browse files
committed
Fix RT 77323: escape all characters outside the normal ASCII range
1 parent 423c2cf commit f636f4b

File tree

3 files changed

+23
-3
lines changed

3 files changed

+23
-3
lines changed

Generator.pm

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1399,7 +1399,7 @@ sub escape {
13991399
}
14001400
}
14011401
if ($f & ESCAPE_HIGH_BIT) {
1402-
$_[0] =~ s/([\200-\377])/'&#'.ord($1).';'/ge;
1402+
$_[0] =~ s/([^\x00-\x7f])/'&#'.ord($1).';'/ge;
14031403
}
14041404
}
14051405

t/DOM.t

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ unless (eval "use XML::DOM; 1;") {
77
exit;
88
}
99

10-
plan tests => 35;
10+
plan tests => 36;
1111

1212
require XML::Generator::DOM;
1313

@@ -23,6 +23,9 @@ ok($xml->toString, '<bar>42</bar>');
2323
$xml = $x->baz({'foo'=>3});
2424
ok($xml->toString, '<baz foo="3"/>');
2525

26+
$xml = $x->password('パスワードをお忘れの方');
27+
ok($xml->toString, '<password>パスワードをお忘れの方</password>');
28+
2629
$xml = $x->bam({'bar'=>42},$x->foo(),"qux");
2730
ok($xml->toString, '<bam bar="42"><foo/>qux</bam>');
2831

t/Generator.t

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
#!/usr/bin/perl -w
22

33
use Test;
4+
use utf8;
45

5-
BEGIN { $| = 1; plan tests => 100; }
6+
BEGIN { $| = 1; plan tests => 105; }
67

78
use XML::Generator ();
89
ok(1);
@@ -260,10 +261,26 @@ ok($xml, '<foo>&lt;
260261
</bar>
261262
</foo>');
262263

264+
$x = XML::Generator->new();
265+
$xml = $x->foo('パスワードをお忘れの方');
266+
ok($xml, '<foo>パスワードをお忘れの方</foo>');
267+
268+
$x = XML::Generator->new(':strict');
269+
$xml = $x->foo('パスワードをお忘れの方');
270+
ok($xml, '<foo>パスワードをお忘れの方</foo>');
271+
ok($xml, "<foo>\x{30D1}\x{30B9}\x{30EF}\x{30FC}\x{30C9}\x{3092}\x{304A}\x{5FD8}\x{308C}\x{306E}\x{65B9}</foo>");
272+
273+
$x = XML::Generator->new(':strict', escape => 'high-bit');
274+
$xml = $x->foo('パスワードをお忘れの方');
275+
ok($xml, '<foo>&#12497;&#12473;&#12527;&#12540;&#12489;&#12434;&#12362;&#24536;&#12428;&#12398;&#26041;</foo>');
276+
263277
$x = XML::Generator->new(':strict', escape => 'high-bit');
264278
$xml = $x->foo("\\<\242", $x->xmlpi('g'));
265279
ok($xml, '<foo><&#162;<?g?></foo>');
266280

281+
$xml = $x->foo("\\<\x{2603}", $x->xmlpi('g'));
282+
ok($xml, '<foo><&#9731;<?g?></foo>');
283+
267284
{ my $w; local $SIG{__WARN__} = sub { $w .= $_[0] };
268285
$x = XML::Generator->new(':import');
269286
ok($w =~ /Useless use of/, 1); $w = '';

0 commit comments

Comments
 (0)