Skip to content

Fix: incorrect strpos check in triggerTagNoCache #1182

Open
zigzagdev wants to merge 1 commit into
smarty-php:masterfrom
zigzagdev:fix/strpos-pattern
Open

Fix: incorrect strpos check in triggerTagNoCache #1182
zigzagdev wants to merge 1 commit into
smarty-php:masterfrom
zigzagdev:fix/strpos-pattern

Conversation

@zigzagdev
Copy link
Copy Markdown
Contributor

Description

Summary

triggerTagNoCache() uses !strpos($variable, '(') to check if ( is absent
from $variable. However, strpos returns 0 when ( appears at position 0,
and !0 evaluates to true, incorrectly skipping the nocache flag logic.

This replaces !strpos(...) with strpos(...) === false.

References

Using `!strpos(...)` incorrectly evaluates to true when `(` is at
position 0, causing the nocache flag logic to be skipped. Replace
with `strpos(...) === false` for correct behavior.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@wisskid
Copy link
Copy Markdown
Member

wisskid commented May 15, 2026

Would this ever be called when when ( is at
position 0?

@zigzagdev
Copy link
Copy Markdown
Contributor Author

@wisskid

Exactly ! You're right — in current usage, ( might not appear at position 0.

But there are two separate concerns:

  1. Current input patterns: May not trigger in this pattern.
  2. Code correctness: strpos() returns 0 at position 0, and !0 evaluates to true which is logically incorrect regardless of current inputs

Even if position 0 doesn't occur now. Because there are three reasons

  1. It's unsafe against the function's contract
  2. It aligns with PHP best practice (PHP docs explicitly recommend === false)
  3. It protects against future refactoring or input format changes

This is a low-risk correctness fix, not just a style improvement.

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.

2 participants