user/dev discussion of public-inbox itself
 help / color / Atom feed
* [PATCH] linkify: support proto://hostname without trailing slash
@ 2019-02-01  7:51 Eric Wong
  0 siblings, 0 replies; 1+ messages 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	[flat|nested] 1+ messages in thread

only message in thread, back to index

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

user/dev discussion of public-inbox itself

Archives are clonable:
	git clone --mirror http://public-inbox.org/meta
	git clone --mirror http://czquwvybam4bgbro.onion/meta
	git clone --mirror http://hjrcffqmbrq6wope.onion/meta
	git clone --mirror http://ou63pmih66umazou.onion/meta

Newsgroups are available over NNTP:
	nntp://news.public-inbox.org/inbox.comp.mail.public-inbox.meta
	nntp://ou63pmih66umazou.onion/inbox.comp.mail.public-inbox.meta
	nntp://czquwvybam4bgbro.onion/inbox.comp.mail.public-inbox.meta
	nntp://hjrcffqmbrq6wope.onion/inbox.comp.mail.public-inbox.meta
	nntp://news.gmane.org/gmane.mail.public-inbox.general

 note: .onion URLs require Tor: https://www.torproject.org/
       or Tor2web: https://www.tor2web.org/

AGPL code for this site: git clone https://public-inbox.org/ public-inbox