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

Add configurable and validatable schemes. #67

Merged

Conversation

glenncoppens
Copy link
Contributor

@glenncoppens glenncoppens commented Dec 7, 2023

Provided is a first approach of configurable but still "validatable" schemes with defaults still in place. As there were a number of issues mentioning this as a "necessary" feature (see: #25, #64 ).

Remarks:

  • I tried to create a basic but open Validator contract and base, definitely open to feedback and improvements.
  • By using a fluent code style (eg: fromString) I scratched my head a bit on how to properly pass in the scheme configuration at the right time. Why? In the fromString method the scheme was (and still is) immediately sanitized and validated, which doesn't leave much room to configure the SchemeValidator. So I've added an optional allowedSchemes parameter.
    • Also I've extracted the "making" of the Url object to comply with "single responsibility" as much as possible
  • I do think that the scheme should be sanitized better using a regex according to https://datatracker.ietf.org/doc/html/rfc3986#section-3.1 (which is defined in the UriInterface)

@freekmurze
Copy link
Member

Some of the tests are failing. Could you take a look? Feel free to up required versions.

@glenncoppens
Copy link
Contributor Author

glenncoppens commented Dec 11, 2023

@freekmurze

Ah, now I see, http-message 1.0 is used in the matrix during 'prefer-lowest' (unfamiliar with the setup).

I'll remove the string typehint again from withScheme(string $scheme) as for now, to still have BC for older http-message versions? Might be better to update the typehints in another PR and then bump the required http-message to ^2.0.

Comin' up!

@glenncoppens
Copy link
Contributor Author

@freekmurze Would you be able to rerun the tests?

@freekmurze
Copy link
Member

Thanks! Could you also update the readme?

@glenncoppens
Copy link
Contributor Author

Done!

@freekmurze freekmurze merged commit e898c99 into spatie:main Jan 5, 2024
12 checks passed
@glenncoppens glenncoppens deleted the feature/configure-and-validate-schemes branch January 19, 2024 14:26
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