Rails auto_link_urls fix for special characters in url

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

([\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).

Comments

Leave a Reply