Repository navigation
Adding WHATWG UrlBuilder - #221
Conversation
|
@kocsismate @kamil-tekiela @TimWolla the new implementation of the polyfill is more inline with PHP implementation but it has one major difference around exception. All exceptions raised in PHP test suite are triggerrd in the polyfill but they differ in the In my builder I generate the candidate URL using WHATWG An example is the following taken from the test on php-src: $builder = new Uri\WhatWg\UrlBuilder();
$builder->setScheme("file");
$builder->setPath("C:/a.txt");
$builder->setPassword("password");
try {
$builder->build();
} catch (Throwable $e) {
echo $e::class, ': ', $e->getMessage(), "\n";
}The expected error is the following Uri\WhatWg\InvalidUrlException: The specified URL cannot have passwordbut my implementation will return Uri\WhatWg\InvalidUrlException: The specified URL is malformed (HostMissing InvalidUrlUnit)because the generated URL is still exposed to the constructor. I presume this is not the case for your implementation. The goal is not to debate who's wrong or right but to highlight that a bad URL can trigger different exception depending on how it is feed to the WHATWG URL spec. |
|
@nyamsprod Thanks for letting us know about this! Yes, the main difference must surely be that the ext/uri implementation relies on the setters with a few "tweaks", while the polyfill apparently uses the basic parser. There was quite a long discussion about this in one of the builder fixes a week ago: php/php-src#23815 (comment) In that thread, I initially wrote that the Builder should behave just like the parser does, but after all, we agreed to rather "copy" the behavior of the setters with our own tweaks (e.g. added base URL support + opaque path support). And later I realized that my original phrasing was not really accurate (that the Builder should follow the regular parser rules), because:
After all, the current implementation generally follows setter rules with some extra validations (e.g. P.S. There are also a few other nuances with error handling on the internal implementation:
|
IMHO the builder API should not be forced into either. The specs define parsing and internal setters, not public builder setters. The builder API should be allowed to do their own preprocessing as long as the underlying result follows the spec. Forcing builder setters into either semantics decreases ergonomics. Another example than what's mentioned here: WHATWG setter (builder) will behave different than the RFC setter (builder; which throws on leading #). |
9ffdb01 to
0d38dec
Compare
A new implementation which is more accurate