Security/Mustache: sniff improvements#842
Merged
Conversation
As things were, double quoted strings with interpolation and PHP 5.3+ nowdocs were not examined. Includes ensuring that all tokens which should be examined have tests associated with them. Note: the `T_STRING` token looks out of place, but is probably included to support JS scanning, though there are no tests for JS files. As support for scanning JS is being removed in PHPCS 4.0, verifying (and probably fixing) JS support by adding tests is not worth spending time on.
Make sure some tests contain more complex PHP interpolated expressions to ensure this doesn't lead to false positives. Note: as I haven't been able to come up with valid code samples which would confuse the Mustache syntax with PHP interpolated expressions, I have not implemented the use of the `TextStrings::stripEmbeds()` method.
…change The sniff didn't have enough guard code to safeguard that the test cases I've added in this commit would be handled correctly. Fixed now.
Includes test.
794ab73 to
0aebe1f
Compare
GaryJones
approved these changes
Jul 17, 2025
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Security/Mustache: sniff for all text string tokens
As things were, double quoted strings with interpolation and PHP 5.3+ nowdocs were not examined.
Includes ensuring that all tokens which should be examined have tests associated with them.
Note: the
T_STRINGtoken in theregisted()method looks out of place, but is probably included to support JS scanning, though there are no tests for JS files.As support for scanning JS is being removed in PHPCS 4.0, verifying (and probably fixing) JS support by adding tests is not worth spending time on.
Security/Mustache: improve tests
Make sure some tests contain more complex PHP interpolated expressions to ensure this doesn't lead to false positives.
Note: as I haven't been able to come up with valid code samples which would confuse the Mustache syntax with PHP interpolated expressions, I have not implemented the use of the
TextStrings::stripEmbeds()method, though that could be considered for the future (would need double-checking that the method does not get confused over the Mustache syntaxes).Security/Mustache: bug fix - potential false positives for delimiter change
The sniff didn't have enough guard code to safeguard that the test cases I've added in this commit would be handled correctly.
Fixed now.
Security/Mustache: prevent false positive on partial text
Includes test.
Closes #541