Links like http://localhost:port/ get rendered incorrectly

Bug #318668 reported by Benno Luthiger
4
Affects Status Importance Assigned to Milestone
Silva
Fix Released
Medium
todd

Bug Description

Problem:
When I enter a link with a URL like http://localhost:8080/something/
this URL is rendered as http://localhost:8082/silva/mysites/mysite/mydir/http://localhost:8080/something/

The problem is caused by
SilvaDocument\mixedcontentsupport.py: line 302 in the _linkHelper() method.

This method should return on line 309 after the URL matches the URL_PATTERN.
However, this pattern doesn't anticipate URLs like http://localhost:8080/x/y/z and therefore the method returns only on line 317 with a unnecessarey prefix added.

The root cause of the problem is that the URL_PATTERN (line 23) wrongly doesn't match a correct url like http://localhost:8080/something/
URL_PATTERN = r'(((http|https|ftp|news)://([A-Za-z0-9%\-_]+(:[A-Za-z0-9%\-_]+)?@)?([A-Za-z0-9\-]+\.)+[A-Za-z0-9]+)(:[0-9]+)?(/([A-Za-z0-9\-_\?!@#$%^&*/=\.]+[^\.\),;\|])?)?|(mailto:[A-Za-z0-9_\-\.]+@([A-Za-z0-9\-]+\.)+[A-Za-z0-9]+))'

I've added the part '(http|https|ftp|news)://localhost(:[0-9]+)?(/([A-Za-z0-9\-_\?!@#$%^&*/=\.]+[^\.\),;\|])?)' as possible fix of this bug:

URL_PATTERN = r'(((http|https|ftp|news)://([A-Za-z0-9%\-_]+(:[A-Za-z0-9%\-_]+)?@)?([A-Za-z0-9\-]+\.)+[A-Za-z0-9]+)(:[0-9]+)?(/([A-Za-z0-9\-_\?!@#$%^&*/=\.]+[^\.\),;\|])?)?|(mailto:[A-Za-z0-9_\-\.]+@([A-Za-z0-9\-]+\.)+[A-Za-z0-9]+)|(http|https|ftp|news)://localhost(:[0-9]+)?(/([A-Za-z0-9\-_\?!@#$%^&*/=\.]+[^\.\),;\|])?))'

As I'm not a regex crack, possibly this could made more efficient.

Kit Blake (kitblake)
Changed in silva:
assignee: nobody → todd-infrae
importance: Undecided → Medium
milestone: none → 2.1
Revision history for this message
todd (todd-infrae) wrote :

Hi Benno(?),

I applied the new regex URL_PATTERN to SilvaDocument-2.1 branch. We should be releasing it soon but I want to confer with Sylvain who may have more changes to add to the release. I've also added a new test to SilvaDocument test_mixedcontentsupport.py that gives you direct access to the link building method.

Todd

Revision history for this message
Andy Altepeter (aaltepet) wrote :

Benno, it looks like this was released with as part of the SilvaDocument 2.1.3 tag in svn.

Changed in silva:
status: New → Fix Released
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.