harrydeluxe / php-liquid

A PHP port of Ruby's Liquid Templates
http://www.delacap.com/artikel/Liquid-Templates/
MIT License
239 stars 119 forks source link

Quotes (escaped) inside "filtered" text or inside a filter's arguments #27

Closed dovid closed 9 years ago

dovid commented 9 years ago

Example of trying to filter some text that has double escaped quotes inside of it:

{{ "let's try some \"quoted\" text" | my_filter }}

Example of trying to filter some text using an argument that has double escaped quotes inside of it:

{{ "text" | my_filter: "let's try some \"quoted\" argument" }}

These are scenarios that I have come across and it appears that the text and argument are both cut off at the first backslash \ because both 'QUOTED_STRING' => '"[^"]*"|\'[^\']*\'' and 'QUOTED_STRING_FILTER_ARGUMENT' => '"[^":]*"|\'[^\':]*\'', are greedy and stop after the first double quote " they find.

It seems that something like this might be a solution:

In \Liquid\Liquid change QUOTED_STRING and QUOTED_STRING_FILTER_ARGUMENT as follows:

'QUOTED_STRING' => '"[^"\\\\]*(?:\\\\.[^"\\\\]*)*"|\'[^\'\\\\]*(?:\\\\.[^\'\\\\]*)*\'',
'QUOTED_STRING_FILTER_ARGUMENT' => '"[^"\\\\]*(?:\\\\.[^"\\\\]*)*"|\'[^\'\\\\]*(?:\\\\.[^\'\\\\]*)*\'',

Thanks @bigwhoop for help on this.

dovid commented 9 years ago

I am closing this issue and re-posted it here https://github.com/kalimatas/php-liquid/issues/4