[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Savannah-hackers-public] Broken links in Savannah news items

From: Sergey Poznyakoff
Subject: Re: [Savannah-hackers-public] Broken links in Savannah news items
Date: Wed, 06 Jul 2016 11:26:12 +0300


> On the contrary, it's good you reported it since it was a bug in the fix :).

Yes, indeed.
> Sergey: it seems to me we can only safely prepend "http://"; if the "www."
> is at ^ or preceded by whitespace.  As in:
>   # Prepare usual links: prefix "www." with "http://";
>   # if it is preceded by whitespace or at the beginning of line.
>   # (don't want to prefix in cases like "//www.." or "ngwww...")
>   $line = preg_replace('/(\s|^)(www\.)/i', '$1http://$2', $line);

Yes, but that breaks expansion of constructs like

  [ main site]
To handle this, the regexp should also include '[', i.e.:

  $line = preg_replace('/(^|\s|\[)(www\.)/i', '$1http://$2', $line);

(full patch attached).

> It's not clear to me what other case is trying to be handled by the
> original alternative of [^/], though surely it was something, and maybe
> we'll hear about it shortly ... 

Apparently the intent was to catch eventual appearance of 'http://' at
the same time allowing expansion when prefixed by another character.  In
particular, that allowed expansion of www\. within double quotes as in
"".  The proposed modification does not allow this.  I
believe we can live with it, though.

Best regards,

>From cd8a3d04c57f21aee5256e261de544acccf3a198 Mon Sep 17 00:00:00 2001
From: Sergey Poznyakoff <address@hidden>
Date: Wed, 6 Jul 2016 10:24:44 +0300
Subject: [PATCH] Fix 72d0512

* frontend/php/include/markup.php: Prepend http:// if 'www.'
appears at the beginning of a line, after a whitespace or [.
 frontend/php/include/markup.php | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/frontend/php/include/markup.php b/frontend/php/include/markup.php
index 41d17c9..5b3d44d 100644
--- a/frontend/php/include/markup.php
+++ b/frontend/php/include/markup.php
@@ -631,10 +631,11 @@ function _markup_inline($line)
   # we can expect web browsers to support)
   $protocols = "https?|ftp|sftp|file|afs|nfs|ircs?";

   # Prepare usual links: prefix every "www." with "http://";
   # unless there is a // before
-  $line = preg_replace('/\b(www\.)/i', 'http://$1', $line);
+  $line = preg_replace('/(^|\s|\[)(www\.)/i', '$1http://$2', $line);
   # replace the @ sign with an HTML entity, if it is used within
   # an url (e.g. for pointers to mailing lists). This way, the
   # @ sign doesn't get mangled in the e-mail markup code

reply via email to

[Prev in Thread] Current Thread [Next in Thread]