This project is archived and is in readonly mode.
auto_link should not create a link inside a link which has the rel attribute
Reported by Kostas K. | December 17th, 2009 @ 09:44 AM
auto_link gets confused when the a tag has something more than the href attribute and relinks inner html of the link
>> a = "<a href=\"http://google.gr\" rel=\"nofollow\">http://google.gr</a>"
=> "<a href=\"http://google.gr\" rel=\"nofollow\">http://google.gr</a>"
>> auto_link(a)
=> "<a href=\"http://google.gr\" rel=\"nofollow\"><a href=\"http://google.gr\">http://google.gr</a></a>"
>> auto_link(a.gsub(/\srel\="nofollow"/, ""))
=> "<a href=\"http://google.gr\">http://google.gr</a>"
sadly enough, I have fixed it locally but can't manage to submit a patch since I can't run the tests (and don't really have much time right now, might try to build a patch next week or something) but here is what seems like it helps a bit:
diff text_helper.rb text_helper_modified.rb
550c550
< if left =~ /<[^>]+$/ && right =~ /^[^>]*>/
---
> if (left =~ /<[^>]+$/ && right =~ /^[^>]*>/) || (left =~ /<a\b[^>]+>$/i && right =~ /^<\/a>/i)
Comments and changes to this ticket
-
Egor Baranov March 29th, 2010 @ 07:20 AM
The solution above does not solve auto_link_urls problem in such situation:
>> auto_link('<a href="http://google.com"><b>http://google.com</b></a>') => <a href="http://google.com"><b><a href="http://google.com">http://google.com</a></b></a>
It's better to use a solution like in attached file
if (left =~ /<[^>]+$/ && right =~ /^[^>]*>/) || (right =~ LINK_CLOSE_TAG_RE && $` !~ LINK_OPEN_TAG_RE)
We try to check if we are in the "A" tag already and if we are in it - do not create link from url.
-
Repository May 29th, 2010 @ 03:06 AM
- State changed from new to resolved
(from [17b4fd25e4de8f05d40ccaa776e51636745aa8e8]) avoid auto_linking already linked emails; more robust detection of linked URLs
References #1523 [#1862 state:resolved] [#3591 state:resolved]
Add test that shows how link text can contain HTML if needed:
the trick is using block form in combination withraw
.
Let link text be automatically HTML-escaped[#2017 state:resolved] http://github.com/rails/rails/commit/17b4fd25e4de8f05d40ccaa776e516...
-
Repository May 29th, 2010 @ 03:06 AM
(from [8f0b2138ee979799092e0489f7298289c90901b9]) avoid auto_linking already linked emails; more robust detection of linked URLs
References #1523 [#1862 state:resolved] [#3591 state:resolved]
Add test that shows how link text can contain HTML if needed:
the trick is using block form in combination withraw
.
Let link text be automatically HTML-escaped[#2017 state:resolved] http://github.com/rails/rails/commit/8f0b2138ee979799092e0489f72982...
-
Jeff Kreeftmeijer November 8th, 2010 @ 08:25 AM
- Tag cleared.
- Importance changed from to Low
Automatic cleanup of spam.
Create your profile
Help contribute to this project by taking a few moments to create your personal profile. Create your profile »
<h2 style="font-size: 14px">Tickets have moved to Github</h2>
The new ticket tracker is available at <a href="https://github.com/rails/rails/issues">https://github.com/rails/rails/issues</a>
People watching this ticket
Attachments
Referenced by
- 1862 Running autolink on text containing a mailto: link breaks References #1523 [#1862 state:resolved] [#3591 state:reso...
- 2017 Should not html_escape auto_link block form References #1523 [#1862 state:resolved] [#3591 state:reso...
- 3591 auto_link should not create a link inside a link which has the rel attribute References #1523 [#1862 state:resolved] [#3591 state:reso...
- 1862 Running autolink on text containing a mailto: link breaks References #1523 [#1862 state:resolved] [#3591 state:reso...
- 3591 auto_link should not create a link inside a link which has the rel attribute References #1523 [#1862 state:resolved] [#3591 state:reso...
- 2017 Should not html_escape auto_link block form References #1523 [#1862 state:resolved] [#3591 state:reso...