php-liquid
php-liquid copied to clipboard
regex for the `cycle` tag gives wrong results
Code to reproduce
{% cycle 44, "one", "three" %}
{% cycle "one", "two", "three" %}
{% cycle "one", "two ::,,ree" %}
{% cycle "one", "two ::,,ree" %}
{% cycle "namedd": "one", "two ::,,ree" %}
Expected output
44
one
one
two ::,,ree
one
Actual output
44
one
one
What happened?
$namedSyntax regex is too greedy, thinking that the strings before the colons are names.
/((?:(?:"[^"]*"|'[^']*')|(?:[^\s,\|'"]|(?:"[^"]*"|'[^']*'))+))\s*\:\s*(.*)/
Its output:
array (size=3)
0 => string 'one", "two ::,,ree" ' (length=20)
1 => string 'one", "two' (length=10)
2 => string ':,,ree" ' (length=8)
array (size=3)
0 => string 'one", "two ::,,ree" ' (length=20)
1 => string 'one", "two' (length=10)
2 => string ':,,ree" ' (length=8)
array (size=3)
0 => string '"namedd": "one", "two ::,,ree" ' (length=31)
1 => string '"namedd"' (length=8)
2 => string '"one", "two ::,,ree" ' (length=21)
I'm crafting new ones to fix this.