Skip to content

Commit 2e6d32a

Browse files
committed
Add Uri\WhatWg classes to ext/uri
Relates to php#14461 and https://wiki.php.net/rfc/url_parsing_api
1 parent 400b7b8 commit 2e6d32a

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

56 files changed

+3299
-8
lines changed

Zend/zend_string.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -597,7 +597,9 @@ EMPTY_SWITCH_DEFAULT_CASE()
597597
_(ZEND_STR_HOST, "host") \
598598
_(ZEND_STR_PORT, "port") \
599599
_(ZEND_STR_USER, "user") \
600+
_(ZEND_STR_USERNAME, "username") \
600601
_(ZEND_STR_PASS, "pass") \
602+
_(ZEND_STR_PASSWORD, "password") \
601603
_(ZEND_STR_PATH, "path") \
602604
_(ZEND_STR_QUERY, "query") \
603605
_(ZEND_STR_FRAGMENT, "fragment") \

build/gen_stub.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3054,6 +3054,8 @@ class PropertyInfo extends VariableLike
30543054
private const PHP_85_KNOWN = [
30553055
"self" => "ZEND_STR_SELF",
30563056
"parent" => "ZEND_STR_PARENT",
3057+
"username" => "ZEND_STR_USERNAME",
3058+
"password" => "ZEND_STR_PASSWORD",
30573059
];
30583060

30593061
/**

ext/lexbor/lexbor/url/url.c

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4442,9 +4442,9 @@ lxb_url_api_hash_set(lxb_url_t *url, lxb_url_parser_t *parser,
44424442
return status;
44434443
}
44444444

4445-
lxb_status_t
4446-
lxb_url_serialize(const lxb_url_t *url, lexbor_serialize_cb_f cb, void *ctx,
4447-
bool exclude_fragment)
4445+
static lxb_status_t
4446+
lxb_url_serialize_body(lxb_unicode_idna_t *idna, const lxb_url_t *url, lexbor_serialize_cb_f cb,
4447+
void *ctx, bool exclude_fragment)
44484448
{
44494449
lxb_status_t status;
44504450
const lexbor_str_t *str;
@@ -4484,7 +4484,12 @@ lxb_url_serialize(const lxb_url_t *url, lexbor_serialize_cb_f cb, void *ctx,
44844484
lexbor_serialize_write(cb, at_str.data, at_str.length, ctx, status);
44854485
}
44864486

4487-
status = lxb_url_serialize_host(&url->host, cb, ctx);
4487+
if (idna != NULL) {
4488+
status = lxb_url_serialize_host_unicode(idna, &url->host, cb, ctx);
4489+
} else {
4490+
status = lxb_url_serialize_host(&url->host, cb, ctx);
4491+
}
4492+
44884493
if (status != LXB_STATUS_OK) {
44894494
return status;
44904495
}
@@ -4529,6 +4534,20 @@ lxb_url_serialize(const lxb_url_t *url, lexbor_serialize_cb_f cb, void *ctx,
45294534
return LXB_STATUS_OK;
45304535
}
45314536

4537+
lxb_status_t
4538+
lxb_url_serialize(const lxb_url_t *url, lexbor_serialize_cb_f cb, void *ctx,
4539+
bool exclude_fragment)
4540+
{
4541+
return lxb_url_serialize_body(NULL, url, cb, ctx, exclude_fragment);
4542+
}
4543+
4544+
lxb_status_t
4545+
lxb_url_serialize_idna(lxb_unicode_idna_t *idna, const lxb_url_t *url, lexbor_serialize_cb_f cb,
4546+
void *ctx, bool exclude_fragment)
4547+
{
4548+
return lxb_url_serialize_body(idna, url, cb, ctx, exclude_fragment);
4549+
}
4550+
45324551
lxb_status_t
45334552
lxb_url_serialize_scheme(const lxb_url_t *url,
45344553
lexbor_serialize_cb_f cb, void *ctx)

ext/lexbor/lexbor/url/url.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -403,6 +403,10 @@ LXB_API lxb_status_t
403403
lxb_url_serialize(const lxb_url_t *url, lexbor_serialize_cb_f cb, void *ctx,
404404
bool exclude_fragment);
405405

406+
LXB_API lxb_status_t
407+
lxb_url_serialize_idna(lxb_unicode_idna_t *idna, const lxb_url_t *url, lexbor_serialize_cb_f cb,
408+
void *ctx, bool exclude_fragment);
409+
406410
LXB_API lxb_status_t
407411
lxb_url_serialize_scheme(const lxb_url_t *url,
408412
lexbor_serialize_cb_f cb, void *ctx);

ext/uri/config.m4

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@ dnl Configure options
22
dnl
33

44
PHP_INSTALL_HEADERS([ext/uri], m4_normalize([
5+
php_lexbor.h
56
php_uri.h
7+
php_uri_common.h
68
]))
79

810
AC_DEFINE([URI_ENABLE_ANSI], [1], [Define to 1 for enabling ANSI support of uriparser.])
@@ -15,6 +17,6 @@ $URIPARSER_DIR/src/UriMemory.c $URIPARSER_DIR/src/UriNormalize.c $URIPARSER_DIR/
1517
$URIPARSER_DIR/src/UriParse.c $URIPARSER_DIR/src/UriParseBase.c $URIPARSER_DIR/src/UriQuery.c \
1618
$URIPARSER_DIR/src/UriRecompose.c $URIPARSER_DIR/src/UriResolve.c $URIPARSER_DIR/src/UriShorten.c"
1719

18-
PHP_NEW_EXTENSION(uri, [php_uri.c $URIPARSER_SOURCES], [no],,[-I$ext_builddir/$URIPARSER_DIR/include -DURI_STATIC_BUILD -DZEND_ENABLE_STATIC_TSRMLS_CACHE=1])
20+
PHP_NEW_EXTENSION(uri, [php_lexbor.c php_uri.c php_uri_common.c $URIPARSER_SOURCES], [no],,[-I$ext_builddir/$URIPARSER_DIR/include -DURI_STATIC_BUILD -DZEND_ENABLE_STATIC_TSRMLS_CACHE=1])
1921
PHP_ADD_EXTENSION_DEP(uri, lexbor)
2022
PHP_ADD_BUILD_DIR($ext_builddir/$URIPARSER_DIR/src $ext_builddir/$URIPARSER_DIR/include)

ext/uri/config.w32

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
EXTENSION("uri", "php_uri.c", false /* never shared */, "/I ext/lexbor /I ext/uri/uriparser/include /DZEND_ENABLE_STATIC_TSRMLS_CACHE=1");
1+
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");
22

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

77
ADD_EXTENSION_DEP('uri', 'lexbor');
88
ADD_SOURCES("ext/uri/uriparser/src", "UriCommon.c UriCompare.c UriEscape.c UriFile.c UriIp4.c UriIp4Base.c UriMemory.c UriNormalize.c UriNormalizeBase.c UriParse.c UriParseBase.c UriQuery.c UriRecompose.c UriShorten.c", "uri");
9-
PHP_INSTALL_HEADERS("ext/uri", "php_uri.h uriparser/src uriparser/include");
9+
PHP_INSTALL_HEADERS("ext/uri", "php_lexbor.h php_uri.h php_uri_common.h uriparser/src uriparser/include");

0 commit comments

Comments
 (0)