Link replacement expression is faulty

mariagwyn - October 12, 2005 - 23:19
Project:Printer-friendly Pages
Version:HEAD
Component:Code
Category:bug report
Priority:minor
Assigned:Unassigned
Status:closed
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

deekayen - December 20, 2005 - 19:45
Version:4.6.x-1.x-dev» HEAD

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 a tag.

#2

deekayen - December 20, 2005 - 20:45

This was my fix. I think this is probably a bug in core, but even if it gets fixed later, the str_replace should 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

deekayen - December 20, 2005 - 20:48
Status:active» fixed

#4

deekayen - December 20, 2005 - 23:36
Status:fixed» active

On second review, I don't think a str_replace will 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

deekayen - December 20, 2005 - 23:44
Status:active» patch (code needs review)

This appears to work as a new pattern for print_generate_node():

    $pattern = "@<a.*?href=([\']?[\"]?)([^\"|^\'|^|^>]*)([^>]*)>(.+?)</a>@ise";

#6

deekayen - December 20, 2005 - 23:57

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

deekayen - December 21, 2005 - 01:03
Priority:normal» minor
Status:patch (code needs review)» active

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

deekayen - December 21, 2005 - 01:04
Title:Open "a" tag in images» Link replacement expression is faulty

#9

deekayen - January 15, 2006 - 04:04

committed the <a.*? to DRUPAL-4-6

#10

jcnventura - August 27, 2007 - 11:51
Status:active» closed

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.

 
 

Drupal is a registered trademark of Dries Buytaert.