Skip to content

ext/uri: Reorganises legacy tests - #23286

Open
NickSdot wants to merge 5 commits into
php:masterfrom
NickSdot:hardening/ext-uri-reorg
Open

ext/uri: Reorganises legacy tests#23286
NickSdot wants to merge 5 commits into
php:masterfrom
NickSdot:hardening/ext-uri-reorg

Conversation

@NickSdot

@NickSdot NickSdot commented Aug 14, 2026

Copy link
Copy Markdown
Contributor

Ref: #23271 (review) @kocsismate
Depends on: #23271 (ready here, but marked as draft until 23271 is merged)

Coverage

Coverage: ext/uri

Base: 5332ab0c291361abe3d12db21dd55e5dc7baa829 upstream/master
Tree: 74844f28e7689f58de3002d41021328750ed0310 working tree

+--------+-------+---------+--------------------+------------------+--------+---------+
|        | Tests | Sources |              Lines |         Branches |   Time |  Memory |
+--------+-------+---------+--------------------+------------------+--------+---------+
| Base   |   374 |       7 | 1697/1934 (87.75%) | 589/968 (60.85%) |  6.49s | 28.0 MB |
| Tree   |   393 |       7 | 1697/1934 (87.75%) | 589/968 (60.85%) |  8.17s | 27.7 MB |
| Change |   +19 |       0 |   +0 / -0 (+0.00%) | +0 / -0 (+0.00%) | +1.69s | -0.2 MB |
+--------+-------+---------+--------------------+------------------+--------+---------+

}
} catch (Throwable $e) {
echo $e::class, ": ", $e->getMessage(), PHP_EOL;
echo $e::class, ': ', $e->getMessage(), "\n";

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.

Since the file now is in git history anyway (move), I unified the style. Cool?

Uri\WhatWg\Url::parse(" https://example.org ", errors: $f->x);
} catch (Throwable $e) {
echo $e::class, ": ", $e->getMessage(), PHP_EOL;
echo $e::class, ': ', $e->getMessage(), "\n";

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.

Same.

@NickSdot NickSdot Aug 15, 2026

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.

Two options for these: keep grouped in eg parsing with zend_ prefix or give dedicated zend dir. Thoughts?

@NickSdot
NickSdot force-pushed the hardening/ext-uri-reorg branch from 74844f2 to d2bfb5c Compare August 15, 2026 14:04
@NickSdot
NickSdot marked this pull request as ready for review August 15, 2026 14:10

@kocsismate kocsismate left a comment

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.

partial review yet, I'll continue later

@@ -1,5 +1,5 @@
--TEST--
Test Uri getters

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.

these cases are already covered by the individual getter tests, aren't they?

<?php

$uri1 = Uri\Rfc3986\Uri::parse("https://example.com");
$uri2 = $uri1->withHost(null);

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.

Why is the host unset here first? And there is no assertion for it. 🤔

I also found https://github.com/php/php-src/blob/65ad51c2faf16d40b0b7b916bfbaba2468ab3f95/ext/uri/tests/rfc3986/modification/host_success_ipv4.phpt and https://github.com/php/php-src/blob/65ad51c2faf16d40b0b7b916bfbaba2468ab3f95/ext/uri/tests/rfc3986/modification/host_success_ipv6.phpt which tests very similar things. So I'm wondering if we need this test in the first place? Does it assert something those tests don't?

<?php

$uri1 = Uri\Rfc3986\Uri::parse("https://example.com");
$uri1->withHost("t%3As%2Ft.com");

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.

The assertion is missing from here

$uri2 = $uri1->withPort(80);

var_dump($uri1->getPort());
var_dump($uri2->getPort());

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.

modification tests also assert the full URI, like here:

var_dump($uri1->getPort());
var_dump($uri2->getPort());
var_dump($uri2->toRawString());

$uri1 = Uri\Rfc3986\Uri::parse("/foo");
$uri2 = $uri1->withPort(null);

var_dump($uri2->getPort());

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.

$uri1->getPort() and the full URI of $uri2 should be asserted as well

@@ -1,17 +1,16 @@
--TEST--
Test percent-encoding normalization - special case
Test Uri\Rfc3986\Uri parsing - path - percent-encoded reserved character

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
Test Uri\Rfc3986\Uri parsing - path - percent-encoded reserved character
Test Uri\Rfc3986\Uri parsing - path - percent-encoded slash character


$url = new Uri\WhatWg\Url("https://example.com/foo/bar%2Fbaz");
var_dump($url->getPath());
var_dump($uri->toRawString());

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.

tests in the parsing directory have the following code for assertions:

var_dump($uri);
var_dump($uri->toRawString());
var_dump($uri->toString());
```


$uri = Uri\Rfc3986\Uri::parse("192.168/contact.html");

var_dump($uri);

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.

the same assertions are needed as mentioned above

--FILE--
<?php

$uri = new Uri\Rfc3986\Uri("mailto:johndoe@example.com");

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.

much of these cases are already covered, please check them (e.g. there is ext/uri/tests/rfc3986/parsing/path_success_relative_reference.phpt and ext/uri/tests/rfc3986/parsing/path_success_relative_reference_absolute.phpt). so probably only mailto:johndoe@example.com and maybe /// is needed (but let's separate them for better readability)

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.

"of" is missing from the test title

@NickSdot

Copy link
Copy Markdown
Contributor Author

partial review yet, I'll continue later

To avoid miscommunication: I plan to address everything in one go when you continued. In case your second pass didn't yield anything new please update me so I know it's done and we do not wait for each other. :)

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.

2 participants