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

regex for the `cycle` tag gives wrong results

Open live627 opened this issue 2 years ago • 0 comments

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.

live627 avatar Feb 11 '23 07:02 live627