Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Class Iri: add input validation #602

Merged
merged 1 commit into from
Nov 8, 2021

Conversation

jrfnl
Copy link
Member

@jrfnl jrfnl commented Nov 7, 2021

The documented accepted parameter type for the constructor of the Iri class is string|null, but no input validation was done on the parameter, which could lead to various PHP errors.

This commit adds input validation to the class constructor, allowing only for strings or null.

As for the other methods:

  • The public magic methods should not need input validation as they should not be called directly, but only indirectly and when called that way, will receive the correct input type.
  • The public static Iri::absolutize() method takes two parameters, both of type \WpOrg\Requests\Iri|string and already validates these parameters to be an instance of Iri and if not, invokes the class constructor, which will now automatically validate the input as string|null.
  • The other public non-static methods do not take parameters.

Includes adding perfunctory tests for the new exception.

The documented accepted parameter type for the constructor of the `Iri` class is `string|null`, but no input validation was done on the parameter, which could lead to various PHP errors.

This commit adds input validation to the class constructor, allowing only for strings or null.

As for the other methods:
* The `public` magic methods should not need input validation as they should not be called directly, but only indirectly and when called that way, will receive the correct input type.
* The `public static` `Iri::absolutize()` method takes two parameters, both of type `\WpOrg\Requests\Iri|string` and already validates these parameters to be an instance of `Iri` and if not, invokes the class constructor, which will now automatically validate the input as `string|null`.
* The other `public` non-static methods do not take parameters.

Includes adding perfunctory tests for the new exception.
@jrfnl jrfnl added this to the 2.0.0 milestone Nov 7, 2021
@jrfnl jrfnl requested a review from schlessera November 7, 2021 02:43
@jrfnl jrfnl mentioned this pull request Nov 7, 2021
28 tasks
@schlessera schlessera merged commit 980de57 into develop Nov 8, 2021
@schlessera schlessera deleted the feature/iri-add-input-validation branch November 8, 2021 09:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants