Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions ext/uri/tests/general/http_stream_error_invalid_uri.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
--TEST--
Test HTTP stream URI parsing - error - invalid URI
--INI--
allow_url_fopen=1
--FILE--
<?php

// hits ext/uri parsing and fails
// before connection is attempted
var_dump(@fopen("http://", "r"));

?>
--EXPECT--
bool(false)
23 changes: 23 additions & 0 deletions ext/uri/tests/general/phpinfo_module_info.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
--TEST--

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.

Debatable if this is worth testing. Thoughts?

Test phpinfo() - URI module information
--FILE--
<?php

ob_start();
phpinfo(INFO_MODULES);
$info = ob_get_clean();

var_dump(str_contains($info, "URI support => active"));
var_dump(
str_contains($info, "uriparser bundled version") ||
(
str_contains($info, "uriparser compiled version")
&&
str_contains($info, "uriparser loaded version")
)
);

?>
--EXPECT--
bool(true)
bool(true)
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
--TEST--
Test Uri\Rfc3986\UriBuilder::build() - error - invalid internal fragment
--EXTENSIONS--
reflection
--FILE--
<?php

$builder = new Uri\Rfc3986\UriBuilder();
new ReflectionProperty($builder, 'fragment')->setValue($builder, '<');

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

?>
--EXPECT--
Uri\InvalidUriException: The specified fragment is malformed
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
--TEST--
Test Uri\Rfc3986\UriBuilder::build() - error - invalid internal host
--EXTENSIONS--
reflection
--FILE--
<?php

$builder = new Uri\Rfc3986\UriBuilder();
new ReflectionProperty($builder, 'host')->setValue($builder, '[');

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

?>
--EXPECT--
Uri\InvalidUriException: The specified host is malformed
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
--TEST--
Test Uri\Rfc3986\UriBuilder::build() - error - invalid internal query
--EXTENSIONS--
reflection
--FILE--
<?php

$builder = new Uri\Rfc3986\UriBuilder();
new ReflectionProperty($builder, 'query')->setValue($builder, '<');

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

?>
--EXPECT--
Uri\InvalidUriException: The specified query is malformed
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
--TEST--
Test Uri\Rfc3986\UriBuilder::build() - error - invalid internal scheme
--EXTENSIONS--
reflection
--FILE--
<?php

$builder = new Uri\Rfc3986\UriBuilder();
new ReflectionProperty($builder, 'scheme')->setValue($builder, ':');

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

?>
--EXPECT--
Uri\InvalidUriException: The specified scheme is malformed
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
--TEST--
Test Uri\Rfc3986\UriBuilder::build() - success - referenced component
--FILE--
<?php

$scope = "\0Uri\\Rfc3986\\UriBuilder\0";

$serialised = serialize(new Uri\Rfc3986\UriBuilder());

$serialised = str_replace(
"s:30:\"{$scope}scheme\";N;",
"s:30:\"{$scope}scheme\";s:5:\"https\";",
$serialised,
);

$serialised = str_replace(
"s:28:\"{$scope}host\";N;",
"s:28:\"{$scope}host\";s:11:\"example.com\";",
$serialised,
);

$serialised = str_replace(
"s:28:\"{$scope}path\";s:0:\"\";",
"s:28:\"{$scope}path\";s:5:\"/path\";",
$serialised,
);

// make fragment share path value
$serialised = str_replace(
"s:32:\"{$scope}fragment\";N;",
"s:32:\"{$scope}fragment\";R:6;",
$serialised,
);

$uri = unserialize($serialised)->build();

var_dump($uri->toRawString());
var_dump($uri);
var_dump($uri->equals(new Uri\Rfc3986\Uri($uri->toRawString())));

?>
--EXPECTF--
string(30) "https://example.com/path#/path"
object(Uri\Rfc3986\Uri)#%d (%d) {
["scheme"]=>
string(5) "https"
["username"]=>
NULL
["password"]=>
NULL
["host"]=>
string(11) "example.com"
["port"]=>
NULL
["path"]=>
string(5) "/path"
["query"]=>
NULL
["fragment"]=>
string(5) "/path"
}
bool(true)
35 changes: 35 additions & 0 deletions ext/uri/tests/rfc3986/builder/host_success_empty.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
--TEST--
Test Uri\Rfc3986\UriBuilder::setHost() - success - empty string
--FILE--
<?php

$builder = new Uri\Rfc3986\UriBuilder();
$builder->setHost('');
$uri = $builder->build();

var_dump($uri->toRawString());
var_dump($uri);
var_dump($uri->equals(new Uri\Rfc3986\Uri($uri->toRawString())));

?>
--EXPECTF--
string(2) "//"
object(Uri\Rfc3986\Uri)#%d (%d) {
["scheme"]=>
NULL
["username"]=>
NULL
["password"]=>
NULL
["host"]=>
string(0) ""
["port"]=>
NULL
["path"]=>
string(0) ""
["query"]=>
NULL
["fragment"]=>
NULL
}
bool(true)
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
--TEST--
Test Uri\Rfc3986\Uri component retrieval - userinfo - without password separator
--FILE--
<?php

$uri = new Uri\Rfc3986\Uri('https://user@example.com');

var_dump($uri->getUserInfo());
var_dump($uri->getUsername());
var_dump($uri->getPassword());

?>
--EXPECT--
string(4) "user"
string(4) "user"
string(0) ""
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
--TEST--
Test Uri\Rfc3986\Uri::withHost() - error - unsetting with port
--FILE--
<?php

$uri = new Uri\Rfc3986\Uri('https://example.com:8080');

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

?>
--EXPECT--
Uri\InvalidUriException: Cannot remove the host from a URI that has a port
14 changes: 14 additions & 0 deletions ext/uri/tests/rfc3986/parsing/port_error_excessive_digits.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
--TEST--
Test Uri\Rfc3986\Uri parsing - port - excessive number of digits
--FILE--
<?php

try {
new \Uri\Rfc3986\Uri('https://example.com:4242424269424242426942424242694242424269');
} catch (Throwable $e) {
echo $e::class, ': ', $e->getMessage(), "\n";
}

?>
--EXPECT--
Uri\InvalidUriException: The port is out of range
12 changes: 0 additions & 12 deletions ext/uri/tests/rfc3986/parsing/port_error_overflow.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,6 @@ Test Uri\Rfc3986\Uri parsing - port - integer overflow
--FILE--
<?php

if (PHP_INT_SIZE == 8) {
$uri = new \Uri\Rfc3986\Uri('https://example.com:9223372036854775807');
echo $uri->getPort(), "\n";
echo "2147483647", "\n";
} else {
$uri = new \Uri\Rfc3986\Uri('https://example.com:2147483647');
echo "9223372036854775807", "\n";
echo $uri->getPort(), "\n";
}

try {
if (PHP_INT_SIZE == 8) {
new \Uri\Rfc3986\Uri('https://example.com:9223372036854775808');
Expand All @@ -25,6 +15,4 @@ try {

?>
--EXPECT--
9223372036854775807
2147483647
Uri\InvalidUriException: The port is out of range
19 changes: 19 additions & 0 deletions ext/uri/tests/rfc3986/parsing/port_success_maximum_integer.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
--TEST--
Test Uri\Rfc3986\Uri parsing - port - maximum integer
--FILE--
<?php

if (PHP_INT_SIZE == 8) {
$uri = new \Uri\Rfc3986\Uri('https://example.com:9223372036854775807');
echo $uri->getPort(), "\n";
echo "2147483647", "\n";
} else {
$uri = new \Uri\Rfc3986\Uri('https://example.com:2147483647');
echo "9223372036854775807", "\n";
echo $uri->getPort(), "\n";
}

?>
--EXPECT--
9223372036854775807
2147483647
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
--TEST--
Test Uri\WhatWg\UrlBuilder::build() - success - multiple validation warnings
--EXTENSIONS--
reflection
--FILE--
<?php

$builder = new Uri\WhatWg\UrlBuilder();

foreach ([
"scheme" => "https",
"host" => "127.0.0.1.",
"path" => "\\foo",
] as $property => $value) {
new ReflectionProperty($builder, $property)->setValue($builder, $value);
}

$url = $builder->build(errors: $errors);

var_dump($url->toAsciiString());
var_dump($url);
foreach ($errors as $error) {
echo $error->type->name, ': ', $error->context, ': ';
var_dump($error->failure);
}
var_dump($url->equals(new Uri\WhatWg\Url($url->toAsciiString())));

?>
--EXPECTF--
string(21) "https://127.0.0.1/foo"
object(Uri\WhatWg\Url)#%d (%d) {
["scheme"]=>
string(5) "https"
["username"]=>
NULL
["password"]=>
NULL
["host"]=>
string(9) "127.0.0.1"
["port"]=>
NULL
["path"]=>
string(4) "/foo"
["query"]=>
NULL
["fragment"]=>
NULL
}
Ipv4EmptyPart: : bool(false)
InvalidReverseSoldius: \foo: bool(false)
bool(true)
Loading
Loading