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);

Comments

dsoneira’s picture

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:

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) ;)

dsoneira’s picture

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.

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'

mrfelton’s picture

Status: Active » Fixed

This is fixed in CVS now.

mrfelton’s picture

Status: Fixed » Patch (to be ported)

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

mrfelton’s picture

Status: Patch (to be ported) » Fixed

Also fixed in the latest D5 code.

Status: Fixed » Closed (fixed)

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