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 |
Jump to:
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
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:
<?phpreturn 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
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.
<?phpreturn 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
This is fixed in CVS now.
#4
marking this as 'to be ported' so I don't forget to backport the changes.
#5
Also fixed in the latest D5 code.
#6
Automatically closed -- issue fixed for 2 weeks with no activity.