Comments

csc4’s picture

Bump - I still seem to have this problem? am I the only one?

Does anyone have a workaround?

pianomansam’s picture

Version: 5.x-1.7 » 5.x-1.12
Component: Code » Code: API (links.inc)
Priority: Normal » Critical

This remains an issue even within 5.x-1.12.

pianomansam’s picture

Status: Active » Needs review

Did a little exploring, found the links_find_links function on line 458. Taking a look at the $patterns['tag'] regular expression (line 467) made me see that the regular expression was not parsing out out HTML tags within the anchor tag. Changing it to exclude tags within the tag seems to have fixed the issue: [^<]

The original line:

  $patterns['tag'] = "%<a href=(?:\"([^\">]+)\"[^>]*|([^\" >]+?)[^>]*)>(.*)</a>%Uis";

The new line:

  $patterns['tag'] = "%<a href=(?:\"([^\">]+)\"[^>]*|([^\" >]+?)[^>]*)>([^<]*)</a>%Uis";
syscrusher’s picture

Close, but not quite. That link fixes *this* bug, but it creates another that I found with my regression testing. I think you're right about the source of the problem, but I still need to tweak your patch before committing. I am busy tonight but will try to get this resolved in the next couple of days.

Scott

syscrusher’s picture

BTW, I didn't mean to sound critical of your patch. It is much appreciated, because it does solve part of the problem. It's just not quite 100% of the fix. :-)

Scott

syscrusher’s picture

Assigned: Unassigned » syscrusher

Request for comment:

I thought about this a bit more, and I think the correct behavior should this:

1. Strip out all HTML tags from the "title" that the existing regexp finds. Whatever text left is the title, if not empty.
2. If that yields no viable title, then look for an "alt" attribute within any HTML tag in the original title string, and use it.
3. If that still yields an empty string, proceed as if there is a title-less link, which the Links module already handles gracefully.

Comments?

Scott

syscrusher’s picture

Add one more:

2a. Look for a "title" attribute on the link tag itself.

Scott

pianomansam’s picture

Close, but not quite. That link fixes *this* bug, but it creates another that I found with my regression testing.

I haven't encountered any bugs from this change. What exactly have you encountered?

syscrusher’s picture

In my test harness, the patch seems to break the ability to find links like these:

<a href="http://test.example.com/page.php"><img src="/some/image.png" alt="image alt attribute one" />title text one</a>
<a href="http://test.example.com/page.php"><img src="/some/image.png" alt="image alt attribute one" /></a>
<a href="http://test.example.com/page.php"><img src="/some/image.png" alt="image alt attribute two">title text two</a>
<a href="http://test.example.com/page.php"><img src="/some/image.png" alt="image alt attribute two"></a>

All four of these are found in the existing release version, although as you point out the title behavior is, err..., suboptimal.

I'm working on an improved version that will find the alt attribute in image tags and use it, if there is no explicit title text.

Scott

syscrusher’s picture

I have just committed developer snapshots of Links for Drupal 5 and Drupal 6 that have my modified patch embedded. If you could please test these on your site and let me know how things are working for you now, I would appreciate it.

In the test cases I showed above (in the code block), the new regexp and additional logic find the title text outside the image tag but within the link tag, if present. Failing that, the new code falls back to the alt attribute from the image.

I will be fixing a couple of additional, unrelated bugs from other issues before releasing this patch to production.

@pianomansam: Thanks again for your patch. I *did* use it as the basis for the new code, and simply added the extra logic I found necessary to cover the additional test cases. Your patch wasn't rejected, just added to. :-)

Scott

pianomansam’s picture

Could you post a patch file for these changes, or post the code lines and changes? I tried running diff on the files and couldn't find any changes pertaining to this issue...

syscrusher’s picture

@pianomansam: Sorry about that. The developer snapshots don't update instantly; I believe it's twice per day on a cron job. Watch the modification dates in the download links and grab the dev release you need (both D5 and D6 versions have this change). You might just want to wait until Tuesday to be sure you get the latest.

Kind regards,

Scott

syscrusher’s picture

Version: 5.x-1.12 » 6.x-2.x-dev

The Drupal 6 dev snapshot didn't update last night. I forgot to update the release settings so it would see the new 6.2 branch. It should update tonight.

Scott

csc4’s picture

Thank you all for all your efforts.

The new branch still doesn't seem to be on the project page but I found it at http://drupal.org/node/24719/release

Sadly, it doesn't seem to have solved my problem.

For

<a class="lightbox-processed" rel="lightbox[triggerlightbox][Bilbo adds his support to K9 Crusaders fundraising]" href="/sites/default/files/shared/events/2008ChristmasFayre/2008-12-01-013%7E1_0.jpg"><img src="/sites/default/files/shared/events/2008ChristmasFayre/2008-12-01-013%7E1.jpg" alt="Bilbo adds his support to K9 Crusaders fundraising" title="Bilbo adds his support to K9 Crusaders fundraising" style="vertical-align: middle;" class="triggerlightbox" height="400" width="386"></a>

I still have

Links from Article Text

    * <img src="/sites/default/files/shared/events/2008ChristmasFayre/2008-12-01-013%7E1.jpg" alt="Bilbo adds his support to K9 Crusaders fundraising" title="Bilbo adds his support to K9 Crusaders fundraising" width="386" height="400" style="vertical-align: middle;" class="triggerlightbox" />