use Template;
use List::Util qw/first/;
use Data::Dumper;
-use URI::Escape qw/uri_escape_utf8/;
+use Encode;
=head1 NAME
$s = $item->{'search'}->[0];
}
#$s =~ s/([^\w.-])/sprintf("%%%02X",ord($1))/eg;
- $s = uri_escape_utf8( $s );
+ $s = __quotemeta( $s );
my $d = $item->{'display'}->[$i] || die "can't find value $i for type display in field $display";
}
+=head2 __quotemeta
+
+Helper to quote JavaScript-friendly characters
+
+=cut
+
+sub __quotemeta {
+ local $_ = shift;
+ $_ = decode('iso-8859-2', $_);
+
+ s<([\x{0080}-\x{fffd}]+)>{sprintf '\u%0*v4X', '\u', $1}ge if ( Encode::is_utf8($_) );
+ {
+ use bytes;
+ s<((?:[^ \x21-\x7E]|(?:\\(?!u)))+)>{sprintf '\x%0*v2X', '\x', $1}ge;
+ }
+
+ s/\\x09/\\t/g;
+ s/\\x0A/\\n/g;
+ s/\\x0D/\\r/g;
+ s/"/\\"/g;
+ s/\\x5C/\\\\/g;
+
+ return $_;
+}
+
=head1 AUTHOR
Dobrica Pavlinusic, C<< <dpavlin@rot13.org> >>