php-liquid icon indicating copy to clipboard operation
php-liquid copied to clipboard

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

Open dovid opened this issue 10 years ago • 2 comments

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 avatar Jan 27 '15 14:01 dovid

That would be great.

usamaejaz avatar Feb 23 '16 08:02 usamaejaz

Hi!

Could please make a pull request with tests for this?

Thanks!

kalimatas avatar Mar 07 '16 19:03 kalimatas