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
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,5 @@ var_dump($url2->toAsciiString());
?>
--EXPECT--
string(8) "password"
NULL
string(0) ""
string(29) "https://username@example.com/"
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
--TEST--
Test Uri\WhatWg\Url component modification - password - unsetting existing
--EXTENSIONS--
uri
--FILE--
<?php

$url1 = Uri\WhatWg\Url::parse("https://:password@example.com");
$url2 = $url1->withPassword(null);

var_dump($url1->getPassword());
var_dump($url2->getPassword());
var_dump($url2->toAsciiString());

?>
--EXPECT--
string(8) "password"
NULL
string(20) "https://example.com/"
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,6 @@ var_dump($url2->toAsciiString());

?>
--EXPECT--
NULL
NULL
string(0) ""
string(0) ""
string(29) "https://username@example.com/"
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,5 @@ var_dump($url2->toAsciiString());
?>
--EXPECT--
string(8) "username"
NULL
string(0) ""
string(30) "https://:password@example.com/"
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
--TEST--
Test Uri\WhatWg\Url component modification - username - unsetting existing
--EXTENSIONS--
uri
--FILE--
<?php

$url1 = Uri\WhatWg\Url::parse("https://username:@example.com");
$url2 = $url1->withUsername(null);

var_dump($url1->getUsername());
var_dump($url2->getUsername());
var_dump($url2->toAsciiString());

?>
--EXPECT--
string(8) "username"
NULL
string(20) "https://example.com/"
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,6 @@ var_dump($url2->toAsciiString());

?>
--EXPECT--
NULL
NULL
string(0) ""
string(0) ""
string(30) "https://:password@example.com/"
10 changes: 8 additions & 2 deletions ext/uri/uri_parser_whatwg.c
Original file line number Diff line number Diff line change
Expand Up @@ -274,11 +274,17 @@ static zend_result php_uri_parser_whatwg_scheme_write(void *uri, zval *value, zv
return SUCCESS;
}

/* 4.2. URL miscellaneous: A URL includes credentials if its username or password is not the empty string. */
static bool includes_credentials(const lxb_url_t *lexbor_uri)
{
return lexbor_uri->username.length > 0 || lexbor_uri->password.length > 0;
}

static zend_result php_uri_parser_whatwg_username_read(void *uri, php_uri_component_read_mode read_mode, zval *retval)
{
const lxb_url_t *lexbor_uri = uri;

if (lexbor_uri->username.length) {
if (includes_credentials(lexbor_uri)) {
ZVAL_STRINGL(retval, (const char *) lexbor_uri->username.data, lexbor_uri->username.length);
} else {
ZVAL_NULL(retval);
Expand Down Expand Up @@ -307,7 +313,7 @@ static zend_result php_uri_parser_whatwg_password_read(void *uri, php_uri_compon
{
const lxb_url_t *lexbor_uri = uri;

if (lexbor_uri->password.length > 0) {
if (includes_credentials(lexbor_uri)) {
ZVAL_STRINGL(retval, (const char *) lexbor_uri->password.data, lexbor_uri->password.length);
} else {
ZVAL_NULL(retval);
Expand Down
Loading