Lighthouse has a new layout. Prefer the old one? Return to the old layout, and switch back any time from the link at the top of each page.

This project is archived and is in readonly mode.

auto_link should not create a link inside a link which has the rel attribute

#3591

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)

Reported by Kostas K. · December 17th, 2009 @ 09:44 AM

State: resolved
Milestone: none
Assigned to: nobody
Importance: Low

Activity

  1. Egor Baranov
    Egor Baranov

    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.

    March 29th, 2010 @ 07:20 AM

  2. Repository
    Repository
    • State changed from new to resolved

    (from [17b4fd25e4de8f05d40ccaa776e51636745aa8e8]) avoid auto_linking already linked emails; more robust detection of linked URLs

    References #1523 auto_link should not linkify URLs in the middle of a tag [#1862 Running autolink on text containing a mailto: link breaks state:resolved] [#3591 auto_link should not create a link inside a link which has the rel attribute state:resolved]

    Add test that shows how link text can contain HTML if needed:
    the trick is using block form in combination with raw.
    Let link text be automatically HTML-escaped

    [#2017 Should not html_escape auto_link block form state:resolved] http://github.com/rails/rails/commit/17b4fd25e4de8f05d40ccaa776e516...

    May 29th, 2010 @ 03:06 AM

  3. Repository
    Repository

    (from [8f0b2138ee979799092e0489f7298289c90901b9]) avoid auto_linking already linked emails; more robust detection of linked URLs

    References #1523 auto_link should not linkify URLs in the middle of a tag [#1862 Running autolink on text containing a mailto: link breaks state:resolved] [#3591 auto_link should not create a link inside a link which has the rel attribute state:resolved]

    Add test that shows how link text can contain HTML if needed:
    the trick is using block form in combination with raw.
    Let link text be automatically HTML-escaped

    [#2017 Should not html_escape auto_link block form state:resolved] http://github.com/rails/rails/commit/8f0b2138ee979799092e0489f72982...

    May 29th, 2010 @ 03:06 AM

  4. Jeff Kreeftmeijer
    Jeff Kreeftmeijer
    • Tag cleared.
    • Importance changed from to Low

    Automatic cleanup of spam.

    November 8th, 2010 @ 08:25 AM