File: filter.t

package info (click to toggle)
liburi-find-perl 20160806-3
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 244 kB
  • sloc: perl: 1,388; makefile: 2
file content (47 lines) | stat: -r--r--r-- 1,418 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#!/usr/bin/perl -w

# Test the filter function

use strict;

use Test::More 'no_plan';

use URI::Find;


my @tasks = (
  ["Foo&Bar http://abc.com.", "Foo&Bar xx&."],
  ["http://abc.com. http://abc.com.", "xx&. xx&."],
  ["http://abc.com?foo=bar&baz=foo", "xx&"],
  ["& http://abc.com?foo=bar&baz=foo", "& xx&"],
  ["http://abc.com?foo=bar&baz=foo &", "xx& &"],
  ["Foo&Bar http://abc.com", "Foo&Bar xx&"],
  ["http://abc.com. Foo&Bar", "xx&. Foo&Bar"],
  ["Foo&Bar http://abc.com. Foo&Bar", "Foo&Bar xx&. Foo&Bar"],
  ["Foo&Bar\nhttp://abc.com.\nFoo&Bar", "Foo&Bar\nxx&.\nFoo&Bar"],
  ["Foo&Bar\nhttp://abc.com. http://def.com.\nFoo&Bar", 
   "Foo&Bar\nxx&. xx&.\nFoo&Bar"],

  # Thing which looks like a URL but isn't
  ["noturi:& should also be escaped", "noturi:& should also be escaped"],

  # Thing which looks like a URL inside brackets, but isn't
  ["Something & <foo://bar&.com> whatever", "Something &amp; <foo://bar&amp;.com> whatever"],

  # Non-URL nested inside brackets
  [q{<a href="foo://example&.com">}, q{<a href="foo://example&amp;.com">}],
);

for my $task (@tasks) {
    my($str, $result) = @$task;
    my $org = $str;
    my $f = URI::Find->new(sub { return "xx&" });
    $f->find(\$str, \&simple_escape);
    is($str, $result, "escape $org");
}

sub simple_escape {
    my($toencode) = @_;
    $toencode =~ s{&}{&amp;}gso;
    return $toencode;
}