Closed (fixed)
Project:
Bbcode
Version:
master
Component:
Code
Priority:
Normal
Category:
Bug report
Assigned:
Reporter:
Created:
22 Jun 2006 at 00:58 UTC
Updated:
22 Jul 2006 at 16:15 UTC
rev 1.47 in CVS introduced this bug... put 'hello http://test.com/test.htm goodbye' into the text and bbcode will leave the "m" out of the URL for the link. Looks like (?!\s) in the regexp is intended to not include a comma in the URL when that comma is followed by a space.. but it omits any final character that is followed by whitespace.
Comments
Comment #1
naudefj commentedPlease try to change
(?!\s)to\b. If it solves the problem, I will commit it to CVS.Comment #2
mindless commentedI think putting a \b there would make a URL followed by ) or < to no longer match.
How about this?
preg_replace('#(?<=^|[\t\r\n >\(])([a-z]+?://[\w-.]+\.([\w-]+\.)*\w+(:[0-9]+)?(/[^ "\'\(;\n\r\t<\)]*)?)((?\1', $ret);
Comment #3
naudefj commentedI've tested the
\bsolution and it seems to work just fine. If there is objection, I will commit it to CVS.Comment #4
mindless commentedyikes, I should have previewed my comment.. forgot < and > would mess it up.
Ok, I now see how \b matches so it will prevent a trailing comma from being included. \b will actually prevent any trailing punctuation or other \W from being included, so something like a://b.c/d?e=f! won't include the ! Not sure if that's a problem.. so you can use \b or the more imposing
((?<!,)|(?!\s))which says "last character is not a comma or next character is not whitespace".. this would allow any character but the designated ones to be at the end of the url.Here is my version with \b
It simplifies the regexp a little bit so you just need \1 in the replacement. It also will match a url at the very beginning of the text.
Comment #5
mindless commentedOne last try, maybe I won't get word wrapped:
<code>$ret = preg_replace('#(?<=^|[\t\r\n >\(])([a-z]+?://[\w\-]+\.([\w\-]+\.)*\w+(:[0-9]+)?(/[^ "\'\(;\n\r\t<\)]*)?)\b#i', '<a href="\1">\1</a>', $ret);Comment #6
naudefj commentedCode committed - see http://drupal.org/cvs?commit=34812
Comment #7
mindless commentedFYI, on our site I removed semicolon from the list of terminating characters for the URL.. this is because we have our own "nohtml" filter that encodes & as & and then bbcode would treat this ; as the end of the URL.
Comment #8
naudefj commentedProbably a good idea. Can you submit a patch?
Comment #9
mindless commentedi just removed a single ; character in the regexp for xxx:// matches, line 194 of bbcode-filter.inc
i suppose some of the changes from line 194 could be applied to line 200 too.
here's another case to consider for \b at the end: test://test.test/test?x=1&y=
ie, a URL that gives y an empty value, and the URL is at the end of a line.
Comment #10
naudefj commentedI trust this will solve the problem - http://drupal.org/cvs?commit=35667
If not, please supply a patch.
Comment #11
mindless commentedLooks good, thanks!
Comment #12
(not verified) commented