Subject: | XPath regex translates literal '=' to ' eq ' |
As posted on http://stackoverflow.com/q/22725248/1733163
Any equal sign inside a xpath regex will be translate to ' eq '. The only hack to avoid this is to use the hex code \x3d. The following script fully reproduces the bug:
use strict;
use warnings;
use XML::Twig;
my $data = do { local $/; <DATA> };
my $t= XML::Twig->new(
twig_handlers => {
q{myelement[@myatt =~ /val=/]}
=> sub { print "/val=/ matches '$_->{att}{myatt}'\n" },
q{myelement[@myatt =~ /val\x3d/]}
=> sub { print "/val\\x3d/ matches '$_->{att}{myatt}'\n" },
},
);
$t->parse( $data );
__DATA__
<root>
<myelement myatt="val eq "/>
<myelement myatt="val="/>
</root>
perl -v
This is perl 5, version 16, subversion 2 (v5.16.2) built for MSWin32-x64-multi-thread
cpan -D XML::Twig
Installed: 3.46
CPAN: 3.46 up to date
Regards,
- Miller