Skip to content

Commit ea81d80

Browse files
committed
Add new tests, path fixes
1 parent b3a48bf commit ea81d80

28 files changed

+216
-119
lines changed

ext/filter/logical_filters.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -613,7 +613,7 @@ void php_filter_validate_url(PHP_INPUT_FILTER_PARAM_DECL) /* {{{ */
613613
}
614614

615615
/* Parse the URI - if it fails, we return NULL */
616-
php_uri *uri = php_uri_parse_to_struct(uri_handler, Z_STR_P(value), URI_COMPONENT_READ_NORMALIZED_MACHINE_FRIENDLY, NULL);
616+
php_uri *uri = php_uri_parse_to_struct(uri_handler, Z_STR_P(value), URI_COMPONENT_READ_NORMALIZED_FOR_MACHINE_PROCESSING, NULL);
617617
if (uri == NULL) {
618618
RETURN_VALIDATION_FAILED
619619
}

ext/soap/php_http.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -439,7 +439,7 @@ int make_http_soap_request(zval *this_ptr,
439439
zend_argument_value_error(6, "must be a valid URI parser name");
440440
return FALSE;
441441
}
442-
uri = php_uri_parse_to_struct(uri_handler, location, URI_COMPONENT_READ_NORMALIZED_MACHINE_FRIENDLY, NULL);
442+
uri = php_uri_parse_to_struct(uri_handler, location, URI_COMPONENT_READ_NORMALIZED_FOR_MACHINE_PROCESSING, NULL);
443443
}
444444

445445
tmp = Z_CLIENT_STREAM_CONTEXT_P(this_ptr);
@@ -1160,7 +1160,7 @@ int make_http_soap_request(zval *this_ptr,
11601160
}
11611161

11621162
zend_string *loc_str = zend_string_init(loc, strlen(loc), false);
1163-
php_uri *new_uri = php_uri_parse_to_struct(uri_handler, loc_str, URI_COMPONENT_READ_NORMALIZED_MACHINE_FRIENDLY, NULL);
1163+
php_uri *new_uri = php_uri_parse_to_struct(uri_handler, loc_str, URI_COMPONENT_READ_NORMALIZED_FOR_MACHINE_PROCESSING, NULL);
11641164
zend_string_release(loc_str);
11651165

11661166
if (new_uri != NULL) {

ext/uri/php_lexbor.c

+15-12
Original file line numberDiff line numberDiff line change
@@ -70,8 +70,8 @@ const uri_handler_t lexbor_uri_handler = {
7070
case URI_COMPONENT_READ_RAW: \
7171
ZVAL_STRINGL(retval, (const char *) start, len); \
7272
break; \
73-
case URI_COMPONENT_READ_NORMALIZED_HUMAN_FRIENDLY: /* Intentional fallthrough */ \
74-
case URI_COMPONENT_READ_NORMALIZED_MACHINE_FRIENDLY: { \
73+
case URI_COMPONENT_READ_NORMALIZED_FOR_DISPLAY: /* Intentional fallthrough */ \
74+
case URI_COMPONENT_READ_NORMALIZED_FOR_MACHINE_PROCESSING: { \
7575
lexbor_str_t *str = lexbor_str_create(); \
7676
lxb_url_host_opt_t opt; \
7777
lxb_status_t result = lxb_url_percent_decode(start, start + len, \
@@ -254,7 +254,9 @@ static lxb_status_t lexbor_serialize_callback(const lxb_char_t *data, size_t len
254254
{
255255
smart_str *uri_str = (smart_str *) ctx;
256256

257-
smart_str_appendl(uri_str, (const char *) data, length);
257+
if (data != NULL && length > 0) {
258+
smart_str_appendl(uri_str, (const char *) data, length);
259+
}
258260

259261
return LXB_STATUS_OK;
260262
}
@@ -264,7 +266,8 @@ static zend_result lexbor_read_scheme(const uri_internal_t *internal_uri, uri_co
264266
lxb_url_t *lexbor_uri = (lxb_url_t *) internal_uri->uri;
265267

266268
ZEND_ASSERT(lexbor_uri->scheme.type != LXB_URL_SCHEMEL_TYPE__UNDEF);
267-
LEXBOR_READ_PERCENT_ENCODED_URI_COMPONENT(lexbor_uri->scheme.name.data, lexbor_uri->scheme.name.length, read_mode, retval);
269+
270+
ZVAL_STRINGL(retval, (const char *) lexbor_uri->scheme.name.data, lexbor_uri->scheme.name.length);
268271

269272
return SUCCESS;
270273
}
@@ -354,7 +357,7 @@ static zend_result lexbor_read_host(const uri_internal_t *internal_uri, uri_comp
354357
} else if (lexbor_uri->host.type != LXB_URL_HOST_TYPE_EMPTY && lexbor_uri->host.type != LXB_URL_HOST_TYPE__UNDEF) {
355358

356359
switch (read_mode) {
357-
case URI_COMPONENT_READ_NORMALIZED_HUMAN_FRIENDLY: {
360+
case URI_COMPONENT_READ_NORMALIZED_FOR_DISPLAY: {
358361
smart_str host_str = {0};
359362
if (lexbor_parser->idna == NULL) {
360363
lexbor_parser->idna = lxb_unicode_idna_create();
@@ -369,7 +372,7 @@ static zend_result lexbor_read_host(const uri_internal_t *internal_uri, uri_comp
369372
ZVAL_STR(retval, smart_str_extract(&host_str));
370373
break;
371374
}
372-
case URI_COMPONENT_READ_NORMALIZED_MACHINE_FRIENDLY: /* Intentional fallthrough */
375+
case URI_COMPONENT_READ_NORMALIZED_FOR_MACHINE_PROCESSING: /* Intentional fallthrough */
373376
case URI_COMPONENT_READ_RAW:
374377
ZVAL_STRINGL(retval, (const char *) lexbor_uri->host.u.domain.data, lexbor_uri->host.u.domain.length);
375378
break;
@@ -425,8 +428,8 @@ static zend_result lexbor_read_path(const uri_internal_t *internal_uri, uri_comp
425428

426429
if (lexbor_uri->path.opaque) {
427430
LEXBOR_READ_PERCENT_ENCODED_URI_COMPONENT(lexbor_uri->path.str.data, lexbor_uri->path.str.length, read_mode, retval);
428-
} else if (lexbor_uri->path.str.length > 1) {
429-
LEXBOR_READ_PERCENT_ENCODED_URI_COMPONENT(lexbor_uri->path.str.data + 1, lexbor_uri->path.str.length - 1, read_mode, retval);
431+
} else if (lexbor_uri->path.str.length) {
432+
LEXBOR_READ_PERCENT_ENCODED_URI_COMPONENT(lexbor_uri->path.str.data, lexbor_uri->path.str.length, read_mode, retval);
430433
} else {
431434
ZVAL_NULL(retval);
432435
}
@@ -561,8 +564,8 @@ static zend_string *lexbor_uri_to_string(void *uri, uri_recomposition_mode_t rec
561564
smart_str uri_str = {0};
562565

563566
switch (recomposition_mode) {
564-
case URI_RECOMPOSITION_HUMAN_FRIENDLY: /* Intentional fallthrough */
565-
case URI_RECOMPOSITION_NORMALIZED_HUMAN_FRIENDLY:
567+
case URI_RECOMPOSITION_FOR_DISPLAY: /* Intentional fallthrough */
568+
case URI_RECOMPOSITION_NORMALIZED_FOR_DISPLAY:
566569
if (lexbor_parser->idna == NULL) {
567570
lexbor_parser->idna = lxb_unicode_idna_create();
568571
lxb_status_t status = lxb_unicode_idna_init(lexbor_parser->idna);
@@ -573,8 +576,8 @@ static zend_string *lexbor_uri_to_string(void *uri, uri_recomposition_mode_t rec
573576
lxb_url_serialize_unicode(lexbor_parser->idna, lexbor_uri, lexbor_serialize_callback, (void *) &uri_str, exclude_fragment);
574577
lxb_unicode_idna_clean(lexbor_parser->idna);
575578
break;
576-
case URI_RECOMPOSITION_MACHINE_FRIENDLY: /* Intentional fallthrough */
577-
case URI_RECOMPOSITION_NORMALIZED_MACHINE_FRIENDLY:
579+
case URI_RECOMPOSITION_FOR_MACHINE_PROCESSING: /* Intentional fallthrough */
580+
case URI_RECOMPOSITION_NORMALIZED_FOR_MACHINE_PROCESSING:
578581
lxb_url_serialize(lexbor_uri, lexbor_serialize_callback, (void *) &uri_str, exclude_fragment);
579582
break;
580583
EMPTY_SWITCH_DEFAULT_CASE()

ext/uri/php_uri.c

+20-25
Original file line numberDiff line numberDiff line change
@@ -450,7 +450,7 @@ PHP_METHOD(Uri_WhatWg_Url, __construct)
450450

451451
PHP_METHOD(Uri_Rfc3986_Uri, getScheme)
452452
{
453-
URI_GETTER(ZSTR_KNOWN(ZEND_STR_SCHEME), URI_COMPONENT_READ_NORMALIZED_MACHINE_FRIENDLY);
453+
URI_GETTER(ZSTR_KNOWN(ZEND_STR_SCHEME), URI_COMPONENT_READ_NORMALIZED_FOR_MACHINE_PROCESSING);
454454
}
455455

456456
PHP_METHOD(Uri_Rfc3986_Uri, getRawScheme)
@@ -465,7 +465,7 @@ PHP_METHOD(Uri_Rfc3986_Uri, withScheme)
465465

466466
PHP_METHOD(Uri_Rfc3986_Uri, getUserInfo)
467467
{
468-
URI_GETTER(ZSTR_KNOWN(ZEND_STR_USERINFO), URI_COMPONENT_READ_NORMALIZED_MACHINE_FRIENDLY);
468+
URI_GETTER(ZSTR_KNOWN(ZEND_STR_USERINFO), URI_COMPONENT_READ_NORMALIZED_FOR_MACHINE_PROCESSING);
469469
}
470470

471471
PHP_METHOD(Uri_Rfc3986_Uri, getRawUserInfo)
@@ -480,7 +480,7 @@ PHP_METHOD(Uri_Rfc3986_Uri, withUserInfo)
480480

481481
PHP_METHOD(Uri_Rfc3986_Uri, getUser)
482482
{
483-
URI_GETTER(ZSTR_KNOWN(ZEND_STR_USER), URI_COMPONENT_READ_NORMALIZED_MACHINE_FRIENDLY);
483+
URI_GETTER(ZSTR_KNOWN(ZEND_STR_USER), URI_COMPONENT_READ_NORMALIZED_FOR_MACHINE_PROCESSING);
484484
}
485485

486486
PHP_METHOD(Uri_Rfc3986_Uri, getRawUser)
@@ -490,7 +490,7 @@ PHP_METHOD(Uri_Rfc3986_Uri, getRawUser)
490490

491491
PHP_METHOD(Uri_Rfc3986_Uri, getPassword)
492492
{
493-
URI_GETTER(ZSTR_KNOWN(ZEND_STR_PASSWORD), URI_COMPONENT_READ_NORMALIZED_MACHINE_FRIENDLY);
493+
URI_GETTER(ZSTR_KNOWN(ZEND_STR_PASSWORD), URI_COMPONENT_READ_NORMALIZED_FOR_MACHINE_PROCESSING);
494494
}
495495

496496
PHP_METHOD(Uri_Rfc3986_Uri, getRawPassword)
@@ -500,7 +500,7 @@ PHP_METHOD(Uri_Rfc3986_Uri, getRawPassword)
500500

501501
PHP_METHOD(Uri_Rfc3986_Uri, getHost)
502502
{
503-
URI_GETTER(ZSTR_KNOWN(ZEND_STR_HOST), URI_COMPONENT_READ_NORMALIZED_MACHINE_FRIENDLY);
503+
URI_GETTER(ZSTR_KNOWN(ZEND_STR_HOST), URI_COMPONENT_READ_NORMALIZED_FOR_MACHINE_PROCESSING);
504504
}
505505

506506
PHP_METHOD(Uri_Rfc3986_Uri, getRawHost)
@@ -515,7 +515,7 @@ PHP_METHOD(Uri_Rfc3986_Uri, withHost)
515515

516516
PHP_METHOD(Uri_Rfc3986_Uri, getPort)
517517
{
518-
URI_GETTER(ZSTR_KNOWN(ZEND_STR_PORT), URI_COMPONENT_READ_NORMALIZED_MACHINE_FRIENDLY);
518+
URI_GETTER(ZSTR_KNOWN(ZEND_STR_PORT), URI_COMPONENT_READ_NORMALIZED_FOR_MACHINE_PROCESSING);
519519
}
520520

521521
PHP_METHOD(Uri_Rfc3986_Uri, withPort)
@@ -525,7 +525,7 @@ PHP_METHOD(Uri_Rfc3986_Uri, withPort)
525525

526526
PHP_METHOD(Uri_Rfc3986_Uri, getPath)
527527
{
528-
URI_GETTER(ZSTR_KNOWN(ZEND_STR_PATH), URI_COMPONENT_READ_NORMALIZED_MACHINE_FRIENDLY);
528+
URI_GETTER(ZSTR_KNOWN(ZEND_STR_PATH), URI_COMPONENT_READ_NORMALIZED_FOR_MACHINE_PROCESSING);
529529
}
530530

531531
PHP_METHOD(Uri_Rfc3986_Uri, getRawPath)
@@ -540,7 +540,7 @@ PHP_METHOD(Uri_Rfc3986_Uri, withPath)
540540

541541
PHP_METHOD(Uri_Rfc3986_Uri, getQuery)
542542
{
543-
URI_GETTER(ZSTR_KNOWN(ZEND_STR_QUERY), URI_COMPONENT_READ_NORMALIZED_MACHINE_FRIENDLY);
543+
URI_GETTER(ZSTR_KNOWN(ZEND_STR_QUERY), URI_COMPONENT_READ_NORMALIZED_FOR_MACHINE_PROCESSING);
544544
}
545545

546546
PHP_METHOD(Uri_Rfc3986_Uri, getRawQuery)
@@ -555,7 +555,7 @@ PHP_METHOD(Uri_Rfc3986_Uri, withQuery)
555555

556556
PHP_METHOD(Uri_Rfc3986_Uri, getFragment)
557557
{
558-
URI_GETTER(ZSTR_KNOWN(ZEND_STR_FRAGMENT), URI_COMPONENT_READ_NORMALIZED_MACHINE_FRIENDLY);
558+
URI_GETTER(ZSTR_KNOWN(ZEND_STR_FRAGMENT), URI_COMPONENT_READ_NORMALIZED_FOR_MACHINE_PROCESSING);
559559
}
560560

561561
PHP_METHOD(Uri_Rfc3986_Uri, getRawFragment)
@@ -585,9 +585,9 @@ static void uri_equals(INTERNAL_FUNCTION_PARAMETERS, zend_object *that_object, b
585585
}
586586

587587
zend_string *this_str = this_internal_uri->handler->uri_to_string(
588-
this_internal_uri->uri, URI_RECOMPOSITION_NORMALIZED_MACHINE_FRIENDLY, exclude_fragment);
588+
this_internal_uri->uri, URI_RECOMPOSITION_NORMALIZED_FOR_MACHINE_PROCESSING, exclude_fragment);
589589
zend_string *that_str = that_internal_uri->handler->uri_to_string(
590-
that_internal_uri->uri, URI_RECOMPOSITION_NORMALIZED_MACHINE_FRIENDLY, exclude_fragment);
590+
that_internal_uri->uri, URI_RECOMPOSITION_NORMALIZED_FOR_MACHINE_PROCESSING, exclude_fragment);
591591

592592
RETVAL_BOOL(zend_string_equals(this_str, that_str));
593593

@@ -617,7 +617,7 @@ PHP_METHOD(Uri_Rfc3986_Uri, toString)
617617
uri_internal_t *internal_uri = uri_internal_from_obj(this_object);
618618
URI_CHECK_INITIALIZATION_RETURN_THROWS(internal_uri, this_object);
619619

620-
RETURN_STR(internal_uri->handler->uri_to_string(internal_uri->uri, URI_RECOMPOSITION_MACHINE_FRIENDLY, false));
620+
RETURN_STR(internal_uri->handler->uri_to_string(internal_uri->uri, URI_RECOMPOSITION_FOR_MACHINE_PROCESSING, false));
621621
}
622622

623623
PHP_METHOD(Uri_Rfc3986_Uri, toNormalizedString)
@@ -628,7 +628,7 @@ PHP_METHOD(Uri_Rfc3986_Uri, toNormalizedString)
628628
uri_internal_t *internal_uri = uri_internal_from_obj(object);
629629
URI_CHECK_INITIALIZATION_RETURN_THROWS(internal_uri, object);
630630

631-
RETVAL_STR(internal_uri->handler->uri_to_string(internal_uri->uri, URI_RECOMPOSITION_NORMALIZED_MACHINE_FRIENDLY, false));
631+
RETVAL_STR(internal_uri->handler->uri_to_string(internal_uri->uri, URI_RECOMPOSITION_NORMALIZED_FOR_MACHINE_PROCESSING, false));
632632
}
633633

634634
PHP_METHOD(Uri_Rfc3986_Uri, resolve)
@@ -644,7 +644,7 @@ PHP_METHOD(Uri_Rfc3986_Uri, resolve)
644644
URI_CHECK_INITIALIZATION_RETURN_THROWS(internal_uri, this_object);
645645

646646
zend_string *base_uri_str = internal_uri->handler->uri_to_string(
647-
internal_uri->uri, URI_RECOMPOSITION_MACHINE_FRIENDLY, false); // TODO optimize by not reparsing the base URI
647+
internal_uri->uri, URI_RECOMPOSITION_FOR_MACHINE_PROCESSING, false); // TODO optimize by not reparsing the base URI
648648

649649
php_uri_instantiate_uri(INTERNAL_FUNCTION_PARAM_PASSTHRU, internal_uri->handler, uri_str, base_uri_str, true, NULL);
650650
}
@@ -665,7 +665,7 @@ PHP_METHOD(Uri_Rfc3986_Uri, __serialize)
665665
}
666666

667667
zval uri_zv;
668-
ZVAL_STR(&uri_zv, internal_uri->handler->uri_to_string(internal_uri->uri, URI_RECOMPOSITION_MACHINE_FRIENDLY, false));
668+
ZVAL_STR(&uri_zv, internal_uri->handler->uri_to_string(internal_uri->uri, URI_RECOMPOSITION_FOR_MACHINE_PROCESSING, false));
669669
zend_hash_str_add_new(result, URI_SERIALIZED_PROPERTY_NAME, sizeof(URI_SERIALIZED_PROPERTY_NAME) - 1, &uri_zv);
670670

671671
ZVAL_ARR(return_value, result);
@@ -747,12 +747,7 @@ PHP_METHOD(Uri_Rfc3986_Uri, __debugInfo)
747747

748748
PHP_METHOD(Uri_WhatWg_Url, getScheme)
749749
{
750-
URI_GETTER(ZSTR_KNOWN(ZEND_STR_SCHEME), URI_COMPONENT_READ_NORMALIZED_MACHINE_FRIENDLY);
751-
}
752-
753-
PHP_METHOD(Uri_WhatWg_Url, getRawScheme)
754-
{
755-
URI_GETTER(ZSTR_KNOWN(ZEND_STR_SCHEME), URI_COMPONENT_READ_RAW);
750+
URI_GETTER(ZSTR_KNOWN(ZEND_STR_SCHEME), URI_COMPONENT_READ_NORMALIZED_FOR_MACHINE_PROCESSING);
756751
}
757752

758753
PHP_METHOD(Uri_WhatWg_Url, withScheme)
@@ -772,12 +767,12 @@ PHP_METHOD(Uri_WhatWg_Url, withPassword)
772767

773768
PHP_METHOD(Uri_WhatWg_Url, getHost)
774769
{
775-
URI_GETTER(ZSTR_KNOWN(ZEND_STR_HOST), URI_COMPONENT_READ_NORMALIZED_MACHINE_FRIENDLY);
770+
URI_GETTER(ZSTR_KNOWN(ZEND_STR_HOST), URI_COMPONENT_READ_NORMALIZED_FOR_MACHINE_PROCESSING);
776771
}
777772

778773
PHP_METHOD(Uri_WhatWg_Url, getHostForDisplay)
779774
{
780-
URI_GETTER(ZSTR_KNOWN(ZEND_STR_HOST), URI_COMPONENT_READ_NORMALIZED_HUMAN_FRIENDLY);
775+
URI_GETTER(ZSTR_KNOWN(ZEND_STR_HOST), URI_COMPONENT_READ_NORMALIZED_FOR_DISPLAY);
781776
}
782777

783778
PHP_METHOD(Uri_WhatWg_Url, withHost)
@@ -819,7 +814,7 @@ PHP_METHOD(Uri_WhatWg_Url, toDisplayString)
819814
uri_internal_t *internal_uri = uri_internal_from_obj(this_object);
820815
URI_CHECK_INITIALIZATION_RETURN_THROWS(internal_uri, this_object);
821816

822-
RETURN_STR(internal_uri->handler->uri_to_string(internal_uri->uri, URI_RECOMPOSITION_HUMAN_FRIENDLY, false));
817+
RETURN_STR(internal_uri->handler->uri_to_string(internal_uri->uri, URI_RECOMPOSITION_FOR_DISPLAY, false));
823818
}
824819

825820
PHP_METHOD(Uri_WhatWg_Url, toString)
@@ -830,7 +825,7 @@ PHP_METHOD(Uri_WhatWg_Url, toString)
830825
uri_internal_t *internal_uri = uri_internal_from_obj(this_object);
831826
URI_CHECK_INITIALIZATION_RETURN_THROWS(internal_uri, this_object);
832827

833-
RETURN_STR(internal_uri->handler->uri_to_string(internal_uri->uri, URI_RECOMPOSITION_MACHINE_FRIENDLY, false));
828+
RETURN_STR(internal_uri->handler->uri_to_string(internal_uri->uri, URI_RECOMPOSITION_FOR_MACHINE_PROCESSING, false));
834829
}
835830

836831
PHP_METHOD(Uri_WhatWg_Url, __unserialize)

ext/uri/php_uri.stub.php

-2
Original file line numberDiff line numberDiff line change
@@ -152,8 +152,6 @@ public function __construct(string $uri, ?string $baseUrl = null, &$softErrors =
152152

153153
public function getScheme(): string {}
154154

155-
public function getRawScheme(): string {}
156-
157155
public function withScheme(string $encodedScheme): static {}
158156

159157
/** @implementation-alias Uri\Rfc3986\Uri::getUser */

ext/uri/php_uri_arginfo.h

+1-5
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

ext/uri/php_uri_common.h

+6-6
Original file line numberDiff line numberDiff line change
@@ -29,16 +29,16 @@ extern zend_class_entry *whatwg_error_type_ce;
2929
extern zend_class_entry *whatwg_error_ce;
3030

3131
typedef enum {
32-
URI_RECOMPOSITION_MACHINE_FRIENDLY,
33-
URI_RECOMPOSITION_HUMAN_FRIENDLY,
34-
URI_RECOMPOSITION_NORMALIZED_HUMAN_FRIENDLY,
35-
URI_RECOMPOSITION_NORMALIZED_MACHINE_FRIENDLY,
32+
URI_RECOMPOSITION_FOR_MACHINE_PROCESSING,
33+
URI_RECOMPOSITION_FOR_DISPLAY,
34+
URI_RECOMPOSITION_NORMALIZED_FOR_MACHINE_PROCESSING,
35+
URI_RECOMPOSITION_NORMALIZED_FOR_DISPLAY,
3636
} uri_recomposition_mode_t;
3737

3838
typedef enum {
3939
URI_COMPONENT_READ_RAW,
40-
URI_COMPONENT_READ_NORMALIZED_HUMAN_FRIENDLY,
41-
URI_COMPONENT_READ_NORMALIZED_MACHINE_FRIENDLY,
40+
URI_COMPONENT_READ_NORMALIZED_FOR_MACHINE_PROCESSING,
41+
URI_COMPONENT_READ_NORMALIZED_FOR_DISPLAY,
4242
} uri_component_read_mode_t;
4343

4444
typedef struct uri_handler_t {

ext/uri/php_uriparser.c

+6-9
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ static zend_result uriparser_normalize_uri(UriUriA *uriparser_uri)
136136
#define URIPARSER_READ_URI(uriparser_uri, uriparser_uris, read_mode) do { \
137137
if (read_mode == URI_COMPONENT_READ_RAW) { \
138138
uriparser_uri = (UriUriA *) uriparser_uris->uri; \
139-
} else if (read_mode == URI_COMPONENT_READ_NORMALIZED_HUMAN_FRIENDLY || read_mode == URI_COMPONENT_READ_NORMALIZED_MACHINE_FRIENDLY) { \
139+
} else if (read_mode == URI_COMPONENT_READ_NORMALIZED_FOR_DISPLAY || read_mode == URI_COMPONENT_READ_NORMALIZED_FOR_MACHINE_PROCESSING) { \
140140
if (uriparser_uris->normalized_uri == NULL) { \
141141
uriparser_uris->normalized_uri = uriparser_copy_uri(uriparser_uris->uri); \
142142
if (uriparser_normalize_uri(uriparser_uris->normalized_uri) == FAILURE) { \
@@ -260,6 +260,10 @@ static zend_result uriparser_read_path(const uri_internal_t *internal_uri, uri_c
260260
const UriPathSegmentA *p;
261261
smart_str str = {0};
262262

263+
if (uriparser_uri->absolutePath || uriIsHostSetA(uriparser_uri)) {
264+
smart_str_appends(&str, "/");
265+
}
266+
263267
smart_str_appendl(&str, uriparser_uri->pathHead->text.first, (int) ((uriparser_uri->pathHead->text).afterLast - (uriparser_uri->pathHead->text).first));
264268

265269
for (p = uriparser_uri->pathHead->next; p != NULL; p = p->next) {
@@ -355,15 +359,8 @@ static void uriparser_append_port(const uri_internal_t *internal_uri, smart_str
355359

356360
static void uriparser_append_path(const uri_internal_t *internal_uri, smart_str *uri_str)
357361
{
358-
uriparser_uris_t *uriparser_uris = (uriparser_uris_t *) internal_uri->uri;
359-
UriUriA *uriparser_uri = uriparser_uris->uri;
360-
361362
zval tmp;
362363

363-
if (uriparser_uri->absolutePath || (uriparser_uri->pathHead != NULL && uriIsHostSetA(uriparser_uri))) {
364-
smart_str_appends(uri_str, "/");
365-
}
366-
367364
uriparser_read_path(internal_uri, URI_COMPONENT_READ_RAW, &tmp);
368365
if (Z_TYPE(tmp) == IS_STRING && Z_STRLEN(tmp) > 0) {
369366
smart_str_append(uri_str, Z_STR(tmp));
@@ -679,7 +676,7 @@ static zend_string *uriparser_uri_to_string(void *uri, uri_recomposition_mode_t
679676
uriparser_uris_t *uriparser_uris = (uriparser_uris_t *) uri;
680677
UriUriA *uriparser_uri = uriparser_uris->uri;
681678

682-
if ((recomposition_mode == URI_RECOMPOSITION_NORMALIZED_HUMAN_FRIENDLY || recomposition_mode == URI_RECOMPOSITION_NORMALIZED_MACHINE_FRIENDLY) &&
679+
if ((recomposition_mode == URI_RECOMPOSITION_NORMALIZED_FOR_DISPLAY || recomposition_mode == URI_RECOMPOSITION_NORMALIZED_FOR_MACHINE_PROCESSING) &&
683680
uriparser_uris->normalized_uri == NULL
684681
) {
685682
uriparser_uris->normalized_uri = uriparser_copy_uri(uriparser_uris->uri);

0 commit comments

Comments
 (0)