Rails auto_link_urls fix for special characters in url

Posted by Rajesh Shetty on February 07, 2008

This one is for Rails 1.1.6. Currently auto_link_urls helper method in text_helper.rb file works well with most of the url’s. It fails to auto link when there are special characters like ~/@/# etc. So here is the quick fix

  • Go to text_helper.rb file under your rails folder.
  • Replace the url segment line from

([\w]+:?[=?&\/.-]?)*    # url segment

to
([\w~,@#\$]+:?[=?&\/.-]?)*    # url segment, added support for ~/,/@/#/$ in urls

Just adding special characters to the regex expression works. BTW I tried porting Rails 1.2 text helper code (which  looks a lot different than this and it does not work).

Trackbacks

Use this link to trackback from your own site.

Comments

Leave a response

Comments