Implement "Followup improvements for ext/uri" RFC - WHATWG URL building - #22268
Implement "Followup improvements for ext/uri" RFC - WHATWG URL building#22268kocsismate wants to merge 8 commits into
Conversation
97cb0bf to
0655d8c
Compare
| goto failure; | ||
| } | ||
|
|
||
| if (lexbor_base_url != NULL) { |
There was a problem hiding this comment.
What's a big shame is that apparently it's not possible to properly use the builder with a base URL :(
- if we try to add the base URL after the input URL is built, then legitimate relative URLs are rejected (e.g.
/foo+https://example.com), because/foois not a valid URL on its own - If we try to build the input URL with the base URL in the same time, then the parsing algorithm must be used (currently, only setters are used with a hack on line 821). Then the complication is to find some URL component that is suitable for parsing:
- for special, full URLs: scheme + host is needed at least (e.g. https://example.com)
- for non-special full URLs: scheme is needed at least (e.g. https://)
- for relative URLs: the path is needed at least (e.g.
/foo/bar)
And in the 2nd case, the question arises if it's ok to parse only the minimally required components and then set the rest of the components, or the whole input URL must be built and parsed all at once.
There was a problem hiding this comment.
I have limited knowledge of lexbor, but can we build a string out of the components we have in the builder, and then call the parser with that? Assuming that we can build the string unambiguously, any errors from missing components would be reported by the parser.
There was a problem hiding this comment.
thanks for the idea! Unfortunately, - as far as I can see the situation - the main blocker is achiveving unambiguous recomposition. E.g.
$builder = new Uri\WhatWg\UrlBuilder();
$builder->setScheme("git");
$builder->setPath("//refs/heads/main");
$builder->build();
This would be recomposed as git://refs/heads/main, however it should rather be git:////refs/heads/main. So overall, we would end up reimplementing the WHATWG URL spec to prevent some cases. Since it's very long specification with a lot of special cases, I wouldn't even dare to attempt this. :(
There was a problem hiding this comment.
Just brainstorming, but would that work?
- base = parse base url
- url = clone base
- for each component in builder:
lxb_url_parse_basic(..., url, base, ..., override_state, ...)(withoverride_statethe state corresponding to this component, e.g.LXB_URL_STATE_PATH_START_STATEfor the path)
0655d8c to
af73d4a
Compare
|
May I have a review soon so that this can potentially be included into alpha 2 at least? :) |
| * The URL is initialized as LXB_URL_SCHEMEL_TYPE__UNDEF but this would prevent the scheme to be updated | ||
| * in case of non-special schemes due to https://github.com/php/php-src/blob/27d7b799c0a13578ee0506b428b8ddc209ffb010/ext/lexbor/lexbor/url/url.c#L1402 | ||
| */ | ||
| if (!php_uri_parser_whatwg_is_special_scheme(scheme)) { |
There was a problem hiding this comment.
I'll try to check if it's something that we can omit somehow...
There was a problem hiding this comment.
I didn't find any way how this workaround could be eliminated...
TimWolla
left a comment
There was a problem hiding this comment.
Had a very superficial first look.
TimWolla
left a comment
There was a problem hiding this comment.
Looked at some tests and some of the C files. Not yet through the PR, but you can likely already make some changes in response to this review.
4a39e3f to
8c50acd
Compare
TimWolla
left a comment
There was a problem hiding this comment.
Went through all tests now. Didn't deeply look at the C code yet, but I'm not super stoked about needing to reimplement the component validation ourselves.
| $builder->setHost("example.com"); | ||
| $builder->setFragment("\tfoo"); | ||
| $errors = []; | ||
| $url = $builder->build(errors: $errors); |
There was a problem hiding this comment.
It seems this is the only test testing $errors.
arnaud-lb
left a comment
There was a problem hiding this comment.
I've only done a partial review yet
9e71a5c to
1fa2162
Compare
…set() (#23144) Originally found in #22268 (comment)
Added lxb_url_parse_host_ipv6() — a public entry point to the IPv6 parser from the WHATWG specification: https://url.spec.whatwg.org/#concept-ipv6-parser The address is accepted both with and without the surrounding square brackets: "::1" and "[::1]" give the same result. #402 The API was requested in #402 for use by php/php-src#22268. Suggested-by: Máté Kocsis (@kocsismate)
- URL: added public IPv6 parser. (lexbor/lexbor@a7dbebbe) - URL: added public percent-encoder API. (lexbor/lexbor@2b24b565)
1fa2162 to
3733c48
Compare
RFC: https://wiki.php.net/rfc/uri_followup#uri_building