Created
November 24, 2011 17:34
-
-
Save leedo/1391865 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| use Test::More; | |
| use Test::Fatal; | |
| use XML::LibXML; | |
| my $escape = sub { | |
| my $string = shift; | |
| $string =~ s/&([^;]+(?:\s|<|$))/&$1/g; | |
| return $string; | |
| }; | |
| my $unescaped = "AT&T"; | |
| my $escaped = "AT&T"; | |
| is($escape->($unescaped), $escaped, "escaped it"); | |
| is($escape->($escaped), $escaped, "didn't re-escape it"); | |
| is($escape->("<b>$unescaped</b>"), "<b>$escaped</b>", "escaped it with tags"); | |
| is($escape->("<b>$escaped</b>"), "<b>$escaped</b>", "didn't re-escape it with tags"); | |
| is( | |
| exception { XML::LibXML->load_xml(string => "<p>".$escape->($unescaped)."</p>") }, | |
| undef, | |
| "parsed unescaped" | |
| ); | |
| is( | |
| exception { XML::LibXML->load_xml(string => "<p>".$escape->($escaped)."</p>") }, | |
| undef, | |
| "parsed escaped" | |
| ); | |
| like( | |
| exception { XML::LibXML->load_xml(string => "<p><b>$unescaped</p>") }, | |
| qr/Opening and ending tag mismatch/, | |
| "error on unclosed tag" | |
| ); | |
| done_testing; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment