Skip to content

Add the Uri\Rfc3986\Uri class to ext/uri without wither support #18836

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 13 commits into
base: master
Choose a base branch
from
Prev Previous commit
Next Next commit
Fixes after rebase
  • Loading branch information
kocsismate committed Jul 1, 2025
commit 7541b3322482c86ba230eab68eb446c1d05f007a
4 changes: 2 additions & 2 deletions ext/uri/config.w32
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
EXTENSION("uri", "php_lexbor.c php_uri.c php_uri_common.c", false /* never shared */, "/I ext/lexbor /I ext/uri/uriparser/include /DZEND_ENABLE_STATIC_TSRMLS_CACHE=1");
EXTENSION("uri", "php_lexbor.c php_uri.c php_uri_common.c php_uriparser.c", false /* never shared */, "/I ext/lexbor /I ext/uri/uriparser/include /DZEND_ENABLE_STATIC_TSRMLS_CACHE=1");

AC_DEFINE("URI_ENABLE_ANSI", 1, "Define to 1 for enabling ANSI support of uriparser.")
AC_DEFINE("URI_NO_UNICODE", 1, "Define to 1 for disabling unicode support of uriparser.")
ADD_FLAG("CFLAGS_URI", "/D URI_STATIC_BUILD");

ADD_EXTENSION_DEP('uri', 'lexbor');
ADD_SOURCES("ext/uri/uriparser/src", "UriCommon.c UriCompare.c UriCopy.c UriEscape.c UriFile.c UriIp4.c UriIp4Base.c UriMemory.c UriNormalize.c UriNormalizeBase.c UriParse.c UriParseBase.c UriQuery.c UriRecompose.c UriResolve.c UriShorten.c", "uri");
PHP_INSTALL_HEADERS("ext/uri", "php_lexbor.h php_uri.h php_uri_common.h uriparser/src uriparser/include");
PHP_INSTALL_HEADERS("ext/uri", "php_lexbor.h php_uri.h php_uri_common.h php_uriparser.h uriparser/src uriparser/include");
4 changes: 2 additions & 2 deletions ext/uri/php_uriparser.c
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Something I'm only noticing now: I think this should rather be called ext/uri/parser_rfc3986.c and php_lexbor.c would be ext/uri/parser_whatwg.c. The php_uriparser.c name is confusing to me, because uriparser is an extremely generic term.

To give another comparison with ext/random, since it is architecturally similar: Each engine has its own engine_enginename.c file, e.g. engine_xoshiro256starstar.c.

Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ static zend_result uriparser_read_host(const uri_internal_t *internal_uri, uri_c
ZEND_ASSERT(uriparser_uri != NULL);

if (uriparser_uri->hostText.first != NULL && uriparser_uri->hostText.afterLast != NULL && get_text_range_length(&uriparser_uri->hostText) > 0) {
if (uriparser_uri->hostData.ip6 != NULL) {
if (uriparser_uri->hostData.ip6 != NULL || uriparser_uri->hostData.ipFuture.first != NULL) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps this needs a comment to explain that the hostText overlaps with ip6 / ipFuture

smart_str host_str = {0};

smart_str_appendc(&host_str, '[');
Expand Down Expand Up @@ -196,7 +196,7 @@ static zend_result uriparser_read_path(const uri_internal_t *internal_uri, uri_c
const UriPathSegmentA *p;
smart_str str = {0};

if (uriparser_uri->absolutePath || uriIsHostSetA(uriparser_uri)) {
if (uriparser_uri->absolutePath || uriHasHostA(uriparser_uri)) {
smart_str_appendc(&str, '/');
}

Expand Down
10 changes: 10 additions & 0 deletions ext/uri/tests/047.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,12 @@ var_dump($uri->getHost());
var_dump($uri->toRawString());
var_dump($uri->toString());

$uri = new Uri\Rfc3986\Uri("//[v7.host]/source");
var_dump($uri->getRawHost());
var_dump($uri->getHost());
var_dump($uri->toRawString());
var_dump($uri->toString());

$url = new Uri\WhatWg\Url("https://192.168.0.1");
var_dump($url->getAsciiHost());
var_dump($url->toAsciiString());
Expand All @@ -39,6 +45,10 @@ string(41) "[2001:0db8:0001:0000:0000:0ab9:C0A8:0102]"
string(41) "[2001:0db8:0001:0000:0000:0ab9:c0a8:0102]"
string(49) "https://[2001:0db8:0001:0000:0000:0ab9:c0a8:0102]"
string(49) "https://[2001:0db8:0001:0000:0000:0ab9:c0a8:0102]"
string(9) "[v7.host]"
string(9) "[v7.host]"
string(18) "//[v7.host]/source"
string(18) "//[v7.host]/source"
string(11) "192.168.0.1"
string(20) "https://192.168.0.1/"
string(26) "[2001:db8:1::ab9:c0a8:102]"
Expand Down
27 changes: 0 additions & 27 deletions ext/uri/uriparser/include/uriparser/Uri.h
Original file line number Diff line number Diff line change
Expand Up @@ -654,33 +654,6 @@ URI_PUBLIC int URI_FUNC(ToString)(URI_CHAR * dest, const URI_TYPE(Uri) * uri,
int maxChars, int * charsWritten);


/**
* Copies a %URI structure.
*
* @param destUri <b>OUT</b>: Output destination
* @param sourceUri <b>IN</b>: %URI to copy
* @param memory <b>IN</b>: Memory manager to use, NULL for default libc
* @return Error code or 0 on success
*
* @since 0.9.8
*/
URI_PUBLIC int URI_FUNC(CopyUriMm)(URI_TYPE(Uri) * destUri,
const URI_TYPE(Uri) * sourceUri, UriMemoryManager * memory);



/**
* Copies a %URI structure.
*
* @param destUri <b>OUT</b>: Output destination
* @param sourceUri <b>IN</b>: %URI to copy
* @return Error code or 0 on success
*
* @since 0.9.8
*/
URI_PUBLIC int URI_FUNC(CopyUri)(URI_TYPE(Uri) * destUri, const URI_TYPE(Uri) * sourceUri);



/**
* Copies a %URI structure.
Expand Down
1 change: 1 addition & 0 deletions ext/uri/uriparser/src/UriCommon.h
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@

/* Used to point to from empty path segments.
* X.first and X.afterLast must be the same non-NULL value then. */
extern const URI_CHAR * const URI_FUNC(SafeToPointTo);
extern const URI_CHAR * const URI_FUNC(ConstPwd);
extern const URI_CHAR * const URI_FUNC(ConstParent);

Expand Down
Loading