* [PATCH] linkify: support proto://hostname without trailing slash
@ 2019-02-01 7:51 Eric Wong
0 siblings, 0 replies; only message in thread
From: Eric Wong @ 2019-02-01 7:51 UTC (permalink / raw)
To: meta
Sometimes users will write "http://example.com" without the
trailing slash, which every browser and tool I've tested seems
to understand.
---
lib/PublicInbox/Linkify.pm | 5 +++--
t/linkify.t | 9 +++++++++
2 files changed, 12 insertions(+), 2 deletions(-)
diff --git a/lib/PublicInbox/Linkify.pm b/lib/PublicInbox/Linkify.pm
index 274f382..aa472cd 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 a55ed22..f0b3a6d 100644
--- a/t/linkify.t
+++ b/t/linkify.t
@@ -14,6 +14,15 @@ use PublicInbox::Linkify;
is($s, qq(<a\nhref="$u">$u</a>.), '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(<a\nhref="$u">$u</a>), 'missing trailing slash OK');
+}
+
# handle URLs in parenthesized statements
{
my $l = PublicInbox::Linkify->new;
--
EW
^ permalink raw reply related [flat|nested] only message in thread
only message in thread, other threads:[~2019-02-01 7:51 UTC | newest]
Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2019-02-01 7:51 [PATCH] linkify: support proto://hostname without trailing slash Eric Wong
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).