Skip to content

ext/uri: Fixes inconsistent validation ordering - #23823

Open
NickSdot wants to merge 4 commits into
php:masterfrom
NickSdot:policy/uri-builder-validation-error-order
Open

NickSdot wants to merge 4 commits into
php:masterfrom
NickSdot:policy/uri-builder-validation-error-order

Conversation

@NickSdot

Copy link
Copy Markdown
Contributor

Aligns builder and parser error order. Parser is LIFO, which is consistent with Lexbor logs (but imo surprising).

Comment thread ext/uri/uri_parser_whatwg.c Outdated
Comment on lines +992 to +993
zval *error;
ZEND_HASH_FOREACH_VAL(Z_ARRVAL(previous_errors), error) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
zval *error;
ZEND_HASH_FOREACH_VAL(Z_ARRVAL(previous_errors), error) {
ZEND_HASH_FOREACH_VAL(Z_ARRVAL(previous_errors), zval *error) {

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

Comment on lines 977 to +979
ZEND_ATTRIBUTE_NONNULL static const char *php_uri_parser_whatwg_build_errors(zval *errors)
{
ZEND_ASSERT(Z_TYPE_P(errors) == IS_ARRAY);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should take a HashTable* directly instead of the assert.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also for php_uri_parser_whatwg_build_errors_into_exception, php_uri_parser_whatwg_build_errors_and_throw, php_uri_parser_whatwg_build_path etc. or only here?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, if possible, use HashTable * (sometimes I also forget about it).

As far as I can see, there's some assertions about errors being undef (e.g. in php_uri_pass_errors_by_ref_and_free(): ZEND_ASSERT(Z_TYPE_P(errors) == IS_UNDEF || Z_TYPE_P(errors) == IS_ARRAY);), but this one at least is likely a dead case, since apparently errors is always an array.

@kocsismate kocsismate Sep 21, 2026

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

although a more general refactoring shouldn't necessarily be done inside this PR, since it can become a rabbit hole.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

although a more general refactoring shouldn't necessarily be done inside this PR, since it can become a rabbit hole.

Done in #23834. Is that fine or does having it split require any additional changes here to address your comment before merge @TimWolla ?

Co-authored-by: Tim Düsterhus <209270+TimWolla@users.noreply.github.com>
@NickSdot

Copy link
Copy Markdown
Contributor Author

Does this need INTERNALS or something?

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.

3 participants