HTML-OSM
view release on metacpan or search on metacpan
t/edge_cases.t view on Meta::CPAN
my (undef, $body) = $m->onload_render();
like($body, qr/$C{LAT_LONDON}/, 'London coord still present after internal mutation risk');
};
# âââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââ
# 13. _js_string() â pathological inputs (white-box, called directly)
# âââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââ
subtest '_js_string: null byte in string passes through (not specially escaped)' => sub {
# Document current behavior: null bytes are not escaped. A future hardening
# pass might change this; the test will catch it.
my $result = HTML::OSM::_js_string("ab\x00cd");
like($result, qr/ab/, 'prefix preserved');
like($result, qr/cd/, 'suffix preserved');
};
subtest '_js_string: only backslash (no quote) input escaped once only' => sub {
# Input: \ (one backslash). Expected: \\ (two backslashes, one escape).
my $result = HTML::OSM::_js_string('\\');
is($result, '\\\\', 'single backslash doubled to double backslash');
};
subtest '_js_string: tab character not escaped (tabs are safe in JS strings)' => sub {
my $result = HTML::OSM::_js_string("a\tb");
is($result, "a\tb", 'tab character passes through unchanged');
};
subtest '_js_string: multiple </script> sequences all escaped' => sub {
my $input = q{</script></script></script>};
my $result = HTML::OSM::_js_string($input);
unlike($result, qr|</script>|, 'no raw </script> in output');
# Each occurrence becomes <\/script>
my @escaped = ($result =~ m{<\\/script>}g);
is(scalar @escaped, 3, 'all three </script> occurrences escaped');
};
subtest '_js_string: very long string (10 000 chars) processed without stack overflow' => sub {
my $long = 'x' x 10_000;
my $r = HTML::OSM::_js_string($long);
is(length($r), 10_000, '10 000-char string length unchanged (no special chars)');
};
subtest '_js_string: all hostile chars combined in one string' => sub {
my $input = "back\\slash quo'te new\nline script</script>end";
my $out = HTML::OSM::_js_string($input);
unlike($out, qr/\n/, 'no literal newline');
unlike($out, qr|</script>|, 'no raw </script>');
like($out, qr/\\'/, 'quote is escaped');
like($out, qr/\\\\/, 'backslash is doubled');
};
# âââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââ
# 14. _validate() â pathological coordinate values (white-box)
# âââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââ
subtest '_validate: very large positive lat rejected' => sub {
local $SIG{__WARN__} = $SILENCE;
is(HTML::OSM::_validate(1e308, 0), 0, 'enormous lat rejected');
};
subtest '_validate: NaN-like string rejected' => sub {
local $SIG{__WARN__} = $SILENCE;
is(HTML::OSM::_validate('NaN', 0), 0, '"NaN" rejected');
};
subtest '_validate: Inf-like string rejected' => sub {
local $SIG{__WARN__} = $SILENCE;
is(HTML::OSM::_validate('Inf', 0), 0, '"Inf" rejected');
};
subtest '_validate: hex string rejected' => sub {
local $SIG{__WARN__} = $SILENCE;
is(HTML::OSM::_validate('0x1F', 0), 0, 'hex "0x1F" rejected');
};
subtest '_validate: JS-injection payload rejected' => sub {
local $SIG{__WARN__} = $SILENCE;
is(HTML::OSM::_validate($C{JS_PAYLOAD}, 0), 0,
'JS-injection payload rejected by _validate');
};
subtest '_validate: leading-decimal with many digits accepted' => sub {
is(HTML::OSM::_validate('.123456789', '.987654321'), 1,
'many decimal places after leading dot accepted');
};
subtest '_validate: both args undef â 0 with no warning' => sub {
my @warns;
local $SIG{__WARN__} = sub { push @warns, @_ };
is(HTML::OSM::_validate(undef, undef), 0, 'undef, undef â 0');
is(scalar @warns, 0, 'no warning when both args are undef');
};
restore_all();
done_testing();
( run in 1.983 second using v1.01-cache-2.11-cpan-60884a8df76 )