IdnaEncoder::encode(): add input validation #592
Merged
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.
The
IdnaEncoder::encode()
is the official entry point for this class, even though there are more public methods (of which it is questionable whether they should be public, but changing that now would be a BC-break).The documented accepted parameter type is
string
, but no input validation was done on the parameter, which could lead to various PHP errors, most notably a "passing null to non-nullable" deprecation notice on PHP 8.1.This commit adds input validation to the
IdnaEncoder::encode()
method, allowing only for strings and stringable objects.While this is stricter than previously, only a string could result in a valid return value, so in my opinion, being strict is warranted.
Includes adding perfunctory tests for the new exception.