Skip to content

Fix if-tag parsing when 'and/or' appear inside string literals#238

Open
petersgecko wants to merge 1 commit intokalimatas:masterfrom
pedros80:fix-if-logical-operator-in-strings
Open

Fix if-tag parsing when 'and/or' appear inside string literals#238
petersgecko wants to merge 1 commit intokalimatas:masterfrom
pedros80:fix-if-logical-operator-in-strings

Conversation

@petersgecko
Copy link

  • I've run the tests with vendor/bin/phpunit
  • None of the tests were found failing
  • I've seen the coverage report at build/coverage/index.html
  • Not a single line left uncovered by tests
  • Any coding standards issues were fixed with vendor/bin/php-cs-fixer fix

(i've not yet managed to run coverage. some tests fail because APC missing etc, but they fail on master on my machine)

Problem

TagIf splits conditions on and / or using a regex across the entire
markup. This incorrectly treats and / or tokens inside quoted string
literals as logical operators, e.g.:

{% if course == "art and design" %}

This results in the condition being split into multiple parts and
evaluated incorrectly.

Solution

  • Respects quoted string literals (single and double quotes)
  • Extracts logical operators only when they appear outside strings
  • Preserves existing behaviour for complex logical expressions
  • Requires no changes to user templates

dunno, is this even a thing?

@sanmai sanmai self-requested a review January 6, 2026 22:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant