From: Eric Wong Date: Fri, 1 Feb 2019 05:27:52 +0000 (+0000) Subject: linkify: support proto://hostname without trailing slash X-Git-Tag: v1.2.0~376 X-Git-Url: http://www.git.stargrave.org/?a=commitdiff_plain;h=58700fb1830d1f854e688dfa47390d7f2eef9035;p=public-inbox.git linkify: support proto://hostname without trailing slash Sometimes users will write "http://example.com" without the trailing slash, which every browser and tool I've tested seems to understand. --- diff --git a/lib/PublicInbox/Linkify.pm b/lib/PublicInbox/Linkify.pm index 274f3820..aa472cdb 100644 --- a/lib/PublicInbox/Linkify.pm +++ b/lib/PublicInbox/Linkify.pm @@ -16,11 +16,12 @@ use Digest::SHA qw/sha1_hex/; my $SALT = rand; my $LINK_RE = qr{(\()?\b((?:ftps?|https?|nntps?|gopher):// - [\@:\w\.-]+/ + [\@:\w\.-]+(?:/ (?:[a-z0-9\-\._~!\$\&\';\(\)\*\+,;=:@/%]*) (?:\?[a-z0-9\-\._~!\$\&\';\(\)\*\+,;=:@/%]+)? (?:\#[a-z0-9\-\._~!\$\&\';\(\)\*\+,;=:@/%\?]+)? - )}xi; + )? + )}xi; sub new { bless {}, $_[0] } diff --git a/t/linkify.t b/t/linkify.t index a55ed22a..f0b3a6d0 100644 --- a/t/linkify.t +++ b/t/linkify.t @@ -14,6 +14,15 @@ use PublicInbox::Linkify; is($s, qq($u.), 'trailing period not in URL'); } +{ + my $l = PublicInbox::Linkify->new; + my $u = 'http://i-forgot-trailing-slash.example.com'; + my $s = $u; + $s = $l->linkify_1($s); + $s = $l->linkify_2($s); + is($s, qq($u), 'missing trailing slash OK'); +} + # handle URLs in parenthesized statements { my $l = PublicInbox::Linkify->new;