Skip to content
Draft
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: 11 additions & 3 deletions ext/lexbor/lexbor/url/url.c
Original file line number Diff line number Diff line change
Expand Up @@ -909,7 +909,7 @@ lxb_url_scheme_copy_special(const lxb_url_scheme_data_t *src,
return lxb_url_str_copy(&src->name, &dst->name, dst_mraw);
}

static void
void
lxb_url_path_set_null(lxb_url_t *url)
{
if (url->path.str.data == NULL) {
Expand Down Expand Up @@ -1133,7 +1133,7 @@ lxb_url_host_destroy(lxb_url_host_t *host, lexbor_mraw_t *mraw)
}
}

static void
void
lxb_url_host_set_empty(lxb_url_host_t *host, lexbor_mraw_t *mraw)
{
lxb_url_host_destroy(host, mraw);
Expand Down Expand Up @@ -1183,7 +1183,15 @@ lxb_url_port_set(lxb_url_t *url, uint16_t port)
url->has_port = true;
}

static void
void
lxb_url_query_set_null(lxb_url_t *url)
{
if (url->query.data != NULL) {
(void) lexbor_str_destroy(&url->query, url->mraw, false);
}
}

void
lxb_url_fragment_set_null(lxb_url_t *url)
{
if (url->fragment.data != NULL) {
Expand Down
12 changes: 12 additions & 0 deletions ext/lexbor/lexbor/url/url.h
Original file line number Diff line number Diff line change
Expand Up @@ -894,6 +894,18 @@ lxb_url_search_params_serialize(lxb_url_search_params_t *search_params,
LXB_API bool
lxb_url_is_special(const lxb_url_t *url);

LXB_API void
lxb_url_path_set_null(lxb_url_t *url);

LXB_API void
lxb_url_host_set_empty(lxb_url_host_t *host, lexbor_mraw_t *mraw);

LXB_API void
lxb_url_query_set_null(lxb_url_t *url);

LXB_API void
lxb_url_fragment_set_null(lxb_url_t *url);

/*
* Inline functions.
*/
Expand Down
2 changes: 0 additions & 2 deletions ext/uri/php_uri.c
Original file line number Diff line number Diff line change
Expand Up @@ -1425,8 +1425,6 @@ PHP_METHOD(Uri_WhatWg_UrlBuilder, build)

lxb_url_t *base_url = NULL;
if (base_url_zv != NULL) {
zend_argument_error(NULL, 1, "is not supported yet, and therefore, null must be passed");
RETURN_THROWS();
base_url = Z_URI_OBJECT_P(base_url_zv)->uri;
}

Expand Down
17 changes: 17 additions & 0 deletions ext/uri/tests/whatwg/builder/basic_error_with_opaque_base.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
--TEST--
Test Uri\WhatWg\UrlBuilder basic - error - with base URL containing opaque path
--FILE--
<?php

$builder = new Uri\WhatWg\UrlBuilder();
$builder->setPath("/foo/bar/baz");

try {
$builder->build(new Uri\WhatWg\Url("scheme:opaque-path"));
} catch (Throwable $e) {
echo $e::class, ': ', $e->getMessage(), "\n";
}

?>
--EXPECT--
Uri\WhatWg\InvalidUrlException: The specified path is malformed (MissingSchemeNonRelativeUrl)
2 changes: 0 additions & 2 deletions ext/uri/tests/whatwg/builder/basic_success_with_base.phpt
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
--TEST--
Test Uri\WhatWg\UrlBuilder basic - success - with base URL
--XFAIL--
Support for passing $baseUrl to Uri\WhatWg\UrlBuilder::build() is not implemented yet.
--FILE--
<?php

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
--TEST--
Test Uri\WhatWg\UrlBuilder basic - success - with scheme relative URL
--FILE--
<?php

$builder = new Uri\WhatWg\UrlBuilder();
$builder->setHost("example.net");
$builder->setPath("/foo/bar/baz");
$builder->setPort(124);
$url = $builder->build(new Uri\WhatWg\Url("https://user:pass@example.com:123/foo/bar?query#hash"));

var_dump($url->toAsciiString());
var_dump($url);
var_dump($url->equals(new Uri\WhatWg\Url($url->toAsciiString())));

?>
--EXPECTF--
string(35) "https://example.net:124/foo/bar/baz"
object(Uri\WhatWg\Url)#%d (%d) {
["scheme"]=>
string(5) "https"
["username"]=>
NULL
["password"]=>
NULL
["host"]=>
string(11) "example.net"
["port"]=>
int(124)
["path"]=>
string(12) "/foo/bar/baz"
["query"]=>
NULL
["fragment"]=>
NULL
}
bool(true)
36 changes: 36 additions & 0 deletions ext/uri/tests/whatwg/builder/fragment_success_with_base.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
--TEST--
Test Uri\WhatWg\UrlBuilder::setFragment() - success - with base URL
--FILE--
<?php

$builder = new Uri\WhatWg\UrlBuilder();
$builder->setFragment("foo");
$url = $builder->build(new Uri\WhatWg\Url("https://example.com/#bar"));

var_dump($url->toAsciiString());
var_dump($url);
var_dump($url->equals(new Uri\WhatWg\Url($url->toAsciiString())));

?>
--EXPECTF--
string(24) "https://example.com/#foo"
object(Uri\WhatWg\Url)#%d (%d) {
["scheme"]=>
string(5) "https"
["username"]=>
NULL
["password"]=>
NULL
["host"]=>
string(11) "example.com"
["port"]=>
NULL
["path"]=>
string(1) "/"
["query"]=>
NULL
["fragment"]=>
string(3) "foo"
}
bool(true)

Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
--TEST--
Test Uri\WhatWg\UrlBuilder::setFragment() - success - with base URL with opaque path
--FILE--
<?php

$builder = new Uri\WhatWg\UrlBuilder();
$builder->setFragment("foo");
$url = $builder->build(new Uri\WhatWg\Url("scheme:opaque-path"));

var_dump($url->toAsciiString());
var_dump($url);
var_dump($url->equals(new Uri\WhatWg\Url($url->toAsciiString())));

?>
--EXPECTF--
string(22) "scheme:opaque-path#foo"
object(Uri\WhatWg\Url)#%d (%d) {
["scheme"]=>
string(6) "scheme"
["username"]=>
NULL
["password"]=>
NULL
["host"]=>
NULL
["port"]=>
NULL
["path"]=>
string(11) "opaque-path"
["query"]=>
NULL
["fragment"]=>
string(3) "foo"
}
bool(true)
17 changes: 17 additions & 0 deletions ext/uri/tests/whatwg/builder/password_error_with_base.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
--TEST--
Test Uri\WhatWg\UrlBuilder::setPassword() - error - missing opaque host with base URL
--FILE--
<?php

$builder = new Uri\WhatWg\UrlBuilder();
$builder->setPassword("password");

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

?>
--EXPECT--
Uri\WhatWg\InvalidUrlException: The specified URL cannot have password
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
--TEST--
Test Uri\WhatWg\UrlBuilder::setPort() - error - missing opaque host with base URL
--FILE--
<?php

$builder = new Uri\WhatWg\UrlBuilder();
$builder->setPort(123);

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

?>
--EXPECT--
Uri\WhatWg\InvalidUrlException: The specified URL cannot have port
35 changes: 35 additions & 0 deletions ext/uri/tests/whatwg/builder/query_success_with_base.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
--TEST--
Test Uri\WhatWg\UrlBuilder::setQuery() - success - with base URL
--FILE--
<?php

$builder = new Uri\WhatWg\UrlBuilder();
$builder->setQuery("foo=bar");
$url = $builder->build(new Uri\WhatWg\Url("https://example.com/?baz"));

var_dump($url->toAsciiString());
var_dump($url);
var_dump($url->equals(new Uri\WhatWg\Url($url->toAsciiString())));

?>
--EXPECTF--
string(28) "https://example.com/?foo=bar"
object(Uri\WhatWg\Url)#%d (%d) {
["scheme"]=>
string(5) "https"
["username"]=>
NULL
["password"]=>
NULL
["host"]=>
string(11) "example.com"
["port"]=>
NULL
["path"]=>
string(1) "/"
["query"]=>
string(7) "foo=bar"
["fragment"]=>
NULL
}
bool(true)
17 changes: 17 additions & 0 deletions ext/uri/tests/whatwg/builder/username_error_with_base.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
--TEST--
Test Uri\WhatWg\UrlBuilder::setUsername() - error - missing opaque host with base URL
--FILE--
<?php

$builder = new Uri\WhatWg\UrlBuilder();
$builder->setUsername("username");

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

?>
--EXPECT--
Uri\WhatWg\InvalidUrlException: The specified URL cannot have username
Loading
Loading