1
0
mirror of https://github.com/php/php-src.git synced 2026-04-27 18:23:26 +02:00

31 Commits

Author SHA1 Message Date
Jordi Kroon fad4323634 Replace google.com with example.com in URI test fixtures (#21807) 2026-04-19 11:31:47 +02:00
Máté Kocsis 48344c9f86 Reorganize ext/uri tests - equivalence (#20391) 2026-01-13 22:45:58 +01:00
Niels Dossche 13d63d6105 Fix GH-20771: Assertion failure when getUnicodeHost() returns empty string
If nothing was added to a smart_str, the interned empty string is
returned, and therefore ZVAL_NEW_STR is wrong as it'll set the
REFCOUNTED flag.

Closes GH-20773.
2025-12-23 23:17:53 +01:00
Máté Kocsis 9743977f92 Fix GH-20366 ext/uri: Do not throw ValueError on null-byte (#20489) 2025-11-19 20:41:27 +01:00
Máté Kocsis 88285c3333 ext/uri: Fix the distinction between an empty and a missing query/fragment for WHATWG URLs (#20208) 2025-11-11 17:05:13 +01:00
Tim Düsterhus 8a0c300d02 uri: Update to uriparser-0.9.9-59-gc3b4956 (#20437)
This is specifically to backport uriparser/uriparser#276.

Fixes php/php-src#20431.
2025-11-11 16:23:27 +01:00
Máté Kocsis cf3b30581d Reorganize ext/uri tests - parsing (#20340) 2025-11-03 21:51:56 +01:00
Máté Kocsis e386864b5a Fix the distinction between missing and empty username/password for RFC3986 URIs (#20335) 2025-11-02 23:33:58 +01:00
Tim Düsterhus a22793db2b uri: Unify exception testing for modification tests (#20368)
Catch any Throwable and print the exact class name.
2025-11-02 22:44:25 +01:00
Tim Düsterhus 81f6ba5503 uri: Use the “includes credentials” rule for WhatWg user/password getters (#20303)
* uri: Use the “includes credentials” rule for WhatWg user/password getters

The URL serializing algorithm from the WHATWG URL Standard uses an “includes
credentials” rule to decide whether or not to include the `@` in the output,
indicating the presence of a userinfo component in RFC 3986 terminology. Use
this rule to determine whether or not an empty username or password should be
returned as the empty string (present but empty) or NULL (not present).

* uri: Use ZVAL_STRINGL_FAST in `whatwg_(username|password)_read()`

This nicely sidesteps the undefined behavior with passing a `(NULL, 0)` pair
without needing manual logic.

* NEWS
2025-11-01 14:15:06 +01:00
Máté Kocsis 27bc7c0e12 Reorganize ext/uri tests - withers (#19970) 2025-10-25 14:46:06 +02:00
Tim Düsterhus 11ce662101 lexbor: Cherry pick "Core: Reset length in lexbor_str_destroy()"
see lexbor/lexbor@1bc9944a19

Fixes php/php-src#19979
2025-09-29 22:43:47 +02:00
Tim Düsterhus 5f00673a45 uri: Fix handling of large port numbers in URI struct (#19905)
* uri: Fix handling of large port numbers in URI struct

* uri: Explain the choice of type for `php_uri.port`

* NEWS
2025-09-21 23:19:54 +02:00
Ilija Tovilo 5897071ab6 Fix refcounting on zend_empty_array in ext-uri (GH-19908)
Fixes GH-19892
2025-09-21 21:56:04 +02:00
Tim Düsterhus d4f5c845ad uri: Throw when trying to modify URI objects after creation (#19768)
This will also fix a memory leak, since the constructor did not free any
pre-existing `->uri`.
2025-09-12 21:00:22 +02:00
Niels Dossche 834e92a4f3 Fix GH-19780: InvalidUrlException should check $errors argument (#19781)
It makes sense to restrict the types used for $errors.
This can also improve the types for static analysis tools as they can
now rely on the array being a list of this class type.

Closes GH-19781.
2025-09-09 22:09:59 +02:00
Tim Düsterhus 156c847467 uri: Fix handling of the errors == NULL && !silent for uri_parser_whatwg (#19748)
* uri: Fix handling of the `errors == NULL && !silent` for uri_parser_whatwg

Previously, when `errors` was `NULL`, the `errors` pointer was used to set the
`$errors` property when throwing the exception, leading to a crash. Use a local
zval to pass the errors to the Exception and copy it into the `errors` input
when it is non-`NULL`.

* uri: Only pass the `errors` zval when interested in it in `php_uri_instantiate_uri()`

This is no longer necessary since the previous commit and also is a layering
violation, since `php_uri_instantiate_uri()` should not care how `parse_uri()`
works internally.

* uri: Use `ZVAL_EMPTY_ARRAY()` when no parsing errors are available

* uri: Avoid redundant refcounting in error handling of uri_parser_whatwg

* NEWS
2025-09-09 00:10:39 +02:00
Máté Kocsis 4e8058e776 Add support for Uri\Rfc3986\Uri withers (#19636)
Related to https://wiki.php.net/rfc/url_parsing_api
2025-09-08 02:30:44 +02:00
Tim Düsterhus 96c4d8b340 uri: Fix handling of empty ports for uri_parser_rfc3986 (#19645)
* uri: Fix handling of empty ports for uri_parser_rfc3986

* NEWS

* uri: Skip the port validation during parsing when port component is empty
2025-09-05 22:55:27 +02:00
Tim Düsterhus 5e9080ff1b uri: Reject ports overflowing zend_long for uri_parser_rfc3986 (#19644)
RFC 3986 technically allows arbitrarily large integers as port numbers, but our
implementation is unable to deal with that, since it expects the port to fit
`zend_long`, reject those explicitly instead of misinterpreting them.
2025-08-31 14:45:31 +02:00
Tim Düsterhus 94678d99ce uri: Fix memory safety violations when assigning $errors by reference fails (#19628)
* uri: Fix double-free when assigning `$errors` by reference fails

`ZEND_TRY_ASSIGN_REF_ARR()` apparently consumes the to-be-assigned value even
when it fails.

* uri: Fix leak of parsed URI when assigning soft errors by reference fails

This is not reproducible, because the URI object will still be referenced by
Lexbor’s mraw instance and then cleanly destroyed at the end of the request.

* NEWS
2025-08-30 21:21:57 +02:00
Tim Düsterhus e99f1b4fcc uri: Fix normalization memory management for uri_parser_php_parse_url.c (#19600)
There were two issues with the previous implementation of normalization:

- `php_raw_url_decode_ex()` would be used to modify a string with RC >1.
- The return value of `php_raw_url_decode_ex()` was not used, resulting in
  incorrect string lengths when percent-encoded characters are decoded.

Additionally there was a bogus assertion that verified that strings returned
from the read handlers are RC =2, which was not the case for the
`parse_url`-based parser when repeatedly retrieving a component even without
normalization happening. Remove that assertion, since its usefulness is
questionable. Any obvious data type issues with read handlers should be
detectable when testing during development.
2025-08-26 23:44:36 +02:00
Tim Düsterhus 423960aad3 uri: Fix lexbor memory management in uri_parser_whatwg.c (#19591)
Calling `lexbor_mraw_clean()` after a specific number of parses will destroy
the data for any live `Uri\WhatWg\Url` objects, effectively resulting in a
use-after-free.

Fix the issue by removing the periodic `lexbor_mraw_clean()` call.  Instead we
implement `php_uri_parser_whatwg_free()`. This also requires to move the
destruction of the lexbor structures from RSHUTDOWN to POST_ZEND_DEACTIVATE to
prevent a use-after-free in `php_uri_parser_whatwg_free()` since otherwise the
mraw would already have been destroyed.
2025-08-26 23:17:21 +02:00
Tim Düsterhus 5fdc02282f uri: Improve exceptions for Uri\Rfc3986\Uri (#19161)
* uri: Streamline implementation of `uriparser_parse_uri_ex()`

Avoid the use of a macro and streamline the logic.

* uri: Improve exceptions for `Uri\Rfc3986\Uri`

* uri: Allow empty URIs for RFC3986

* NEWS

* uri: Improve ext/uri/tests/004.phpt for empty URIs
2025-07-18 17:38:44 +02:00
Máté Kocsis 967377369b Fix parsing URIs with empty hosts
Both RFC 3986 and WHATWG support empty hosts
2025-07-15 22:28:44 +02:00
Máté Kocsis 889f38135d Cherry pick some recent lexbor changes
The following changes are cherry-picked:
- https://github.com/lexbor/lexbor/commit/c60846689d3f516bddd3f6ff1f20cf721bd67b79 core/str.c: Fix undefined behavior in function lexbor_str_append
- https://github.com/lexbor/lexbor/commit/92260fd6709247c0fc324b1d59efb53ba16db27e URL: fixed hostname setter if port is specified.
2025-07-15 22:28:16 +02:00
Máté Kocsis 5a9f5a6514 Add the Uri\Rfc3986\Uri class to ext/uri without wither support (#18836)
Relates to #14461 and https://wiki.php.net/rfc/url_parsing_api

Co-authored-by: Niels Dossche <7771979+nielsdos@users.noreply.github.com>
Co-authored-by: Tim Düsterhus <tim@tideways-gmbh.com>
2025-07-05 10:00:20 +02:00
Tim Düsterhus ec8b016d08 uri: Do not create new UrlValidationErrorType objects (#19009)
`zend_enum_new()` is not intended to be used “at runtime”, since it will create
a new object, breaking the singleton property. Instead
`zend_enum_get_case_cstr()` must be used.
2025-07-02 13:57:50 +02:00
Gina Peter Banyard 4ff8d9f6b4 ext/uri: Remove bool type coercions in tests (#18921) 2025-06-23 13:49:20 +01:00
Tim Düsterhus 81865ec5bd uri: Improve exceptions for Uri\WhatWg\Url (#18855)
A more specific exception message is used, while the code is simplified.
2025-06-23 12:14:00 +02:00
Máté Kocsis 3399235bec Add Uri\WhatWg classes to ext/uri (#18672)
Relates to #14461 and https://wiki.php.net/rfc/url_parsing_api

Co-authored-by: Niels Dossche <7771979+nielsdos@users.noreply.github.com>
Co-authored-by: Tim Düsterhus <tim@tideways-gmbh.com>
2025-06-10 10:18:22 +02:00