Add FILTER_VALIDATE_STRLEN for UTF-8 string length validation#21429
Open
masakielastic wants to merge 7 commits intophp:masterfrom
Open
Add FILTER_VALIDATE_STRLEN for UTF-8 string length validation#21429masakielastic wants to merge 7 commits intophp:masterfrom
masakielastic wants to merge 7 commits intophp:masterfrom
Conversation
Implements min/max string length validation according to Unicode Standard 3.9.6. Adds Unicode and invalid UTF-8 test cases.
Upstream changed filter handler return type from void to zend_result. Update php_filter_validate_str() and related declarations accordingly.
The validator checks the length of a UTF-8 string in Unicode code points. Renaming improves clarity and aligns the filter name with the min_len / max_len options.
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.
This PR introduces a new filter validator FILTER_VALIDATE_STRLEN.
The validator checks the length of a UTF-8 string in Unicode code points and allows applications to enforce minimum and/or maximum string length.
API
New filter constant:
Supported options:
Example:
Implementation notes
The implementation:
htmlspecialchars)Motivation
Validating the length of UTF-8 strings is a common requirement in applications (e.g. form input validation).
Currently this is typically implemented in userland using:
mb_strlen()from thembstringextensionProviding a dedicated validator in the filter extension allows this validation to be performed in a lightweight and consistent way without introducing a dependency on
mbstring.Related discussion
See issue #21428