This turns out to be a bug in s/// in perl-5.8.0. This patch works
around it:
diff -ru XML-Twig-3.12/Twig.pm XML-Twig-3.12-new/Twig.pm
--- XML-Twig-3.12/Twig.pm Thu Jan 29 16:50:14 2004
+++ XML-Twig-3.12-new/Twig.pm Sun Feb 1 11:16:28 2004
@@ -3243,15 +3243,31 @@
sub safe_encode
{ my $str= shift;
- $str =~ s{([\xC0-\xDF].|[\xE0-\xEF]..|[\xF0-\xFF]...)}
+ if ($] == 5.008)
+ { # Bug in perl stops s///g working properly.
+ 0 while
+ $str =~ s{([\xC0-\xDF].|[\xE0-\xEF]..|[\xF0-\xFF]...)}
+ {XmlUtf8Decode($1)}es;
+ }
+ else
+ { $str =~ s{([\xC0-\xDF].|[\xE0-\xEF]..|[\xF0-\xFF]...)}
{XmlUtf8Decode($1)}egs;
+ }
return $str;
}
sub safe_encode_hex
{ my $str= shift;
- $str =~ s{([\xC0-\xDF].|[\xE0-\xEF]..|[\xF0-\xFF]...)}
+ if ($] == 5.008)
+ { # Bug in perl stops s///g working properly.
+ 0 while
+ $str =~ s{([\xC0-\xDF].|[\xE0-\xEF]..|[\xF0-\xFF]...)}
+ {XmlUtf8Decode($1, 1)}es;
+ }
+ else
+ { $str =~ s{([\xC0-\xDF].|[\xE0-\xEF]..|[\xF0-\xFF]...)}
{XmlUtf8Decode($1, 1)}egs;
+ }
return $str;
}
diff -ru XML-Twig-3.12/Twig.pm.slow XML-Twig-3.12-new/Twig.pm.slow
--- XML-Twig-3.12/Twig.pm.slow Thu Jan 29 15:28:52 2004
+++ XML-Twig-3.12-new/Twig.pm.slow Sun Feb 1 11:16:24 2004
@@ -3243,15 +3243,31 @@
sub safe_encode
{ my $str= shift;
- $str =~ s{([\xC0-\xDF].|[\xE0-\xEF]..|[\xF0-\xFF]...)}
+ if ($] == 5.008)
+ { # Bug in perl stops s///g working properly.
+ 0 while
+ $str =~ s{([\xC0-\xDF].|[\xE0-\xEF]..|[\xF0-\xFF]...)}
+ {XmlUtf8Decode($1)}es;
+ }
+ else
+ { $str =~ s{([\xC0-\xDF].|[\xE0-\xEF]..|[\xF0-\xFF]...)}
{XmlUtf8Decode($1)}egs;
+ }
return $str;
}
sub safe_encode_hex
{ my $str= shift;
- $str =~ s{([\xC0-\xDF].|[\xE0-\xEF]..|[\xF0-\xFF]...)}
+ if ($] == 5.008)
+ { # Bug in perl stops s///g working properly.
+ 0 while
+ $str =~ s{([\xC0-\xDF].|[\xE0-\xEF]..|[\xF0-\xFF]...)}
+ {XmlUtf8Decode($1, 1)}es;
+ }
+ else
+ { $str =~ s{([\xC0-\xDF].|[\xE0-\xEF]..|[\xF0-\xFF]...)}
{XmlUtf8Decode($1, 1)}egs;
+ }
return $str;
}
The patch is against both Twig.pm.slow and Twig.pm since both files are
included in the source distribution.
If you don't want to apply this patch, please add a check to Makefile.PL
to make sure 5.8.0 is not being used (eg require at least 5.8.1).