Extend to Single Quotes as Well?

Bairnsfather - September 13, 2006 - 20:24
Project:Path Filter
Version:6.x-1.0
Component:Code
Category:feature request
Priority:normal
Assigned:Unassigned
Status:closed
Description

This filter is awesome and just what I was looking for, but it only works with double quotes. Could you update the process function (lines 79 &80) so that it also filters when within single quotes?

The reason I ask is I have a JavaScript where the path is single quoted and this filter doesn't work.

I'd patch this but I really have very little clue about GREP (I think that's what this is), it looks more like cartoon cursing than something I know how to read. :-)

Here are the two lines in question:

          return preg_replace('/"internal:([^"#\?]+)\??([^"#]+)?#?([^"]+)?"/e',
              "'\"'. url('$1', '$2' ? '$2' : NULL, '$3' ? '$3' : NULL, ". $absolute .") .'\"'", $text);

#1

daniel.soneira - March 24, 2008 - 14:33
Version:4.7.x-1.x-dev» 6.x-1.0

I'm facing the same problem when I want to use this filter with a javascript call like this one:

onClick="window.open('internal:node/52','Popup title','width=765,height=610,resizable=yes,scrollbars=yes');return false;"

Here is my changed code. This solution does not break the double quote (standard) links. Maybe it is helpful for someone having a similar issue:

<?php
return preg_replace('/(["\'])internal:([^"#\?\']+)\??([^"#\']+)?#?([^"\']+)?["\']/e',
             
"stripcslashes('$1'). url('$2', array('query' => '$3' ? '$3' : NULL, 'fragment' => '$4' ? '$4' : NULL, 'absolute' => ". $absolute .")) .stripcslashes('$1')", $text);
?>

Please note: I did not look into doing anything pretty - I just wanted to make it work (fast) ;)

#2

daniel.soneira - March 27, 2008 - 18:54

Here is an improved version with a back reference (\1) at the end, so that whatever is used to start the expression (single or double quotes) has also to end it.

My first try (see last post) also matches "internal:node/52' - which is incorrect.

<?php
return preg_replace('/(["\'])internal:([^"#\?\']+)\??([^"#\']+)?#?([^"\']+)?(\1)/e',
             
"stripcslashes('$1'). url('$2', array('query' => '$3' ? '$3' : NULL, 'fragment' => '$4' ? '$4' : NULL, 'absolute' => ". $absolute .")) .stripcslashes('$1')", $text);
?>

Now it's either "internal:double_quotes" or 'internal:single_quotes'

#3

mrfelton - May 7, 2009 - 19:34
Status:active» fixed

This is fixed in CVS now.

#4

mrfelton - May 16, 2009 - 17:58
Status:fixed» patch (to be ported)

marking this as 'to be ported' so I don't forget to backport the changes.

#5

mrfelton - October 17, 2009 - 13:35
Status:patch (to be ported)» fixed

Also fixed in the latest D5 code.

#6

System Message - October 31, 2009 - 13:40
Status:fixed» closed

Automatically closed -- issue fixed for 2 weeks with no activity.

 
 

Drupal is a registered trademark of Dries Buytaert.