Link replacement expression is faulty
mariagwyn - October 12, 2005 - 23:19
| Project: | Printer, e-mail and PDF versions |
| Version: | 7.x-1.x-dev |
| Component: | Code |
| Category: | bug report |
| Priority: | minor |
| Assigned: | Unassigned |
| Status: | closed |
Jump to:
Description
My print friendly pages appear to have an open 'a' tag around images which have been inserted using img_assist. So, the code is something like this:
<a ><u><img width="250" height="255" alt="image" src="/files/images/image.jpg" /></u> [1] I am not sure if this is a problem with the print.module or the img_assist.module.
For an example, go to:
http://www.stnina.org/node/25/print
and take a look at the code.
Any ideas?
Thanks,
Maria

#1
I'm guessing it's not img_assist, since with today's CVS version of print and Drupal 4.7, file attachments have the same open
atag.#2
This was my fix. I think this is probably a bug in core, but even if it gets fixed later, the
str_replaceshould be harmless (unless for some reason people actually want<a <u>in their node).<?php print str_replace('<a <u>', '<u>', $node->body); ?>It's committed to CVS for Drupal 4.7 (but not tagged for 4.7 packaging). Needs backport for older versions.
#3
#4
On second review, I don't think a
str_replacewill do the whole job. Though I haven't verfied it, according to the preg_replace pattern in the source,<a target="_blank" href="...would produce<a target="_blank" <u>after replacement. It's probably going to need a fancier replacement expression or another one to cleanup after the first.#5
This appears to work as a new pattern for
print_generate_node():$pattern = "@<a.*?href=([\']?[\"]?)([^\"|^\'|^|^>]*)([^>]*)>(.+?)</a>@ise";#6
This breaks the regex for properly counting URLs in HREF values, but I don't think I can really spend the time to make a regex to prevent it from breaking the link counter:
<a target="href=" href="http://test.com"style="border: 1px solid red">test</a>#7
I committed the
<a.*?part of the pattern to replace the str_replace solution. I'll leave this open as a minor issue for figuring out the previous post's breakage example.#8
#9
committed the
<a.*?to DRUPAL-4-6#10
deekayen had mostly fixed the problem, but to solve the problem that he pointed out earlier, I re-wrote the tag parsing mechanism so that only href or src elements are handled. This is now in the latest 5.x dev release.