1 # Copyright (C) 2016-2018 all contributors <meta@public-inbox.org>
2 # License: AGPL-3.0+ <https://www.gnu.org/licenses/agpl-3.0.txt>
6 use PublicInbox::Linkify;
9 my $l = PublicInbox::Linkify->new;
10 my $u = 'http://example.com/url-with-trailing-period';
12 $s = $l->linkify_1($s);
13 $s = $l->linkify_2($s);
14 is($s, qq(<a\nhref="$u">$u</a>.), 'trailing period not in URL');
18 my $l = PublicInbox::Linkify->new;
19 my $u = 'http://i-forgot-trailing-slash.example.com';
21 $s = $l->linkify_1($s);
22 $s = $l->linkify_2($s);
23 is($s, qq(<a\nhref="$u">$u</a>), 'missing trailing slash OK');
26 # handle URLs in parenthesized statements
28 my $l = PublicInbox::Linkify->new;
29 my $u = 'http://example.com/';
31 $s = $l->linkify_1($s);
32 $s = $l->linkify_2($s);
33 is($s, qq{(see: <a\nhref="$u">$u</a>)}, 'trailing ) not in URL');
37 my $l = PublicInbox::Linkify->new;
38 my $u = 'http://example.com/url-with-trailing-semicolon';
40 $s = $l->linkify_1($s);
41 $s = $l->linkify_2($s);
42 is($s, qq(<a\nhref="$u">$u</a>;), 'trailing semicolon not in URL');
46 my $l = PublicInbox::Linkify->new;
47 my $u = 'http://example.com/url-with-(parens)';
48 my $s = "hello $u world";
49 $s = $l->linkify_1($s);
50 $s = $l->linkify_2($s);
51 is($s, qq(hello <a\nhref="$u">$u</a> world), 'URL preserved');
54 $s = "hello $u world";
55 $s = $l->linkify_1($s);
56 $s = $l->linkify_2($s);
57 is($s, qq(hello <a\nhref="$u">$u</a> world), 'query preserved');
60 $s = "hello $u world";
61 $s = $l->linkify_1($s);
62 $s = $l->linkify_2($s);
63 is($s, qq(hello <a\nhref="$u">$u</a> world),
64 'query + fragment preserved');
66 $u = "http://example.com/";
67 $s = "hello $u world";
68 $s = $l->linkify_1($s);
69 $s = $l->linkify_2($s);
70 is($s, qq(hello <a\nhref="$u">$u</a> world), "root URL preserved");
72 $u = "http://example.com/#fragment";
73 $s = "hello $u world";
74 $s = $l->linkify_1($s);
75 $s = $l->linkify_2($s);
76 is($s, qq(hello <a\nhref="$u">$u</a> world), "root + fragment");
79 # Markdown compatibility
81 my $l = PublicInbox::Linkify->new;
82 my $u = 'http://example.com/';
83 my $s = "[markdown]($u)";
84 $s = $l->linkify_1($s);
85 $s = $l->linkify_2($s);
86 is($s, qq![markdown](<a\nhref="$u">$u</a>)!, 'Markdown-compatible');
88 $s = qq![markdown]($u "title")!;
89 $s = $l->linkify_1($s);
90 $s = $l->linkify_2($s);
91 is($s, qq![markdown](<a\nhref="$u">$u</a> "title")!,
92 'Markdown title compatible');
94 $s = qq![markdown]($u).!;
95 $s = $l->linkify_1($s);
96 $s = $l->linkify_2($s);
97 is($s, qq![markdown](<a\nhref="$u">$u</a>).!,
98 'Markdown-compatible end of sentence');