Skip to content

Commit d0b9a3d

Browse files
committed
A lot of fixes and API changes
1 parent b4a48c2 commit d0b9a3d

Some content is hidden

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

55 files changed

+1961
-1715
lines changed

Diff for: ext/dom/lexbor/lexbor/url/url.c

+88-14
Original file line numberDiff line numberDiff line change
@@ -40,14 +40,6 @@ typedef enum {
4040
}
4141
lxb_url_map_type_t;
4242

43-
typedef enum {
44-
LXB_URL_HOST_OPT_UNDEF = 0 << 0,
45-
LXB_URL_HOST_OPT_NOT_SPECIAL = 1 << 0,
46-
LXB_URL_HOST_OPT_DECODE = 1 << 1,
47-
LXB_URL_HOST_OPT_IDNA = 1 << 2
48-
}
49-
lxb_url_host_opt_t;
50-
5143
typedef struct {
5244
lexbor_mraw_t *mraw;
5345
lexbor_str_t *str;
@@ -599,11 +591,6 @@ lxb_url_opaque_host_parse(lxb_url_parser_t *parser, const lxb_char_t *data,
599591
const lxb_char_t *end, lxb_url_host_t *host,
600592
lexbor_mraw_t *mraw);
601593

602-
static lxb_status_t
603-
lxb_url_percent_decode(const lxb_char_t *data, const lxb_char_t *end,
604-
lexbor_str_t *str, lexbor_mraw_t *mraw,
605-
lxb_url_host_opt_t *opt);
606-
607594
static const lxb_char_t *
608595
lxb_url_path_part_by_index(const lxb_url_t *url, size_t index,
609596
size_t *out_length);
@@ -3961,7 +3948,7 @@ lxb_url_opaque_host_parse(lxb_url_parser_t *parser, const lxb_char_t *data,
39613948
LXB_URL_MAP_C0, false);
39623949
}
39633950

3964-
static lxb_status_t
3951+
lxb_status_t
39653952
lxb_url_percent_decode(const lxb_char_t *data, const lxb_char_t *end,
39663953
lexbor_str_t *str, lexbor_mraw_t *mraw,
39673954
lxb_url_host_opt_t *opt)
@@ -4523,6 +4510,93 @@ lxb_url_serialize(const lxb_url_t *url, lexbor_serialize_cb_f cb, void *ctx,
45234510
return LXB_STATUS_OK;
45244511
}
45254512

4513+
lxb_status_t
4514+
lxb_url_serialize_unicode(lxb_unicode_idna_t *idna, const lxb_url_t *url, lexbor_serialize_cb_f cb, void *ctx,
4515+
bool exclude_fragment)
4516+
{
4517+
lxb_status_t status;
4518+
const lexbor_str_t *str;
4519+
lxb_char_t *p;
4520+
lxb_char_t buf[LXB_URL_BUFFER_NUM_SIZE];
4521+
4522+
static const lexbor_str_t colon_str = lexbor_str(":");
4523+
static const lexbor_str_t dsol_str = lexbor_str("//");
4524+
static const lexbor_str_t at_str = lexbor_str("@");
4525+
static const lexbor_str_t dt_str = lexbor_str("/.");
4526+
static const lexbor_str_t qm_str = lexbor_str("?");
4527+
static const lexbor_str_t hs_str = lexbor_str("#");
4528+
4529+
/* Scheme. */
4530+
4531+
str = &url->scheme.name;
4532+
4533+
lexbor_serialize_write(cb, str->data, str->length, ctx, status);
4534+
lexbor_serialize_write(cb, colon_str.data, colon_str.length, ctx, status);
4535+
4536+
/* Host. */
4537+
4538+
if (url->host.type != LXB_URL_HOST_TYPE__UNDEF) {
4539+
lexbor_serialize_write(cb, dsol_str.data, dsol_str.length, ctx, status);
4540+
4541+
if (lxb_url_includes_credentials(url)) {
4542+
lexbor_serialize_write(cb, url->username.data, url->username.length,
4543+
ctx, status);
4544+
4545+
if (url->password.length != 0) {
4546+
lexbor_serialize_write(cb, colon_str.data, colon_str.length,
4547+
ctx, status);
4548+
lexbor_serialize_write(cb, url->password.data,
4549+
url->password.length, ctx, status);
4550+
}
4551+
4552+
lexbor_serialize_write(cb, at_str.data, at_str.length, ctx, status);
4553+
}
4554+
4555+
status = lxb_url_serialize_host_unicode(idna, &url->host, cb, ctx);
4556+
if (status != LXB_STATUS_OK) {
4557+
return status;
4558+
}
4559+
4560+
if (url->has_port) {
4561+
lexbor_serialize_write(cb, colon_str.data, colon_str.length,
4562+
ctx, status);
4563+
4564+
p = buf + lexbor_conv_int64_to_data((int64_t) url->port,
4565+
buf, LXB_URL_BUFFER_NUM_SIZE);
4566+
4567+
lexbor_serialize_write(cb, buf, p - buf, ctx, status);
4568+
}
4569+
}
4570+
else if (!url->path.opaque && url->path.str.length > 1) {
4571+
str = &url->path.str;
4572+
4573+
if (str->data[0] == '/' && str->data[1] == '/') {
4574+
lexbor_serialize_write(cb, dt_str.data, dt_str.length, ctx, status);
4575+
}
4576+
}
4577+
4578+
status = lxb_url_serialize_path(&url->path, cb, ctx);
4579+
if (status != LXB_STATUS_OK) {
4580+
return status;
4581+
}
4582+
4583+
if (url->query.data != NULL) {
4584+
lexbor_serialize_write(cb, qm_str.data, qm_str.length,
4585+
ctx, status);
4586+
lexbor_serialize_write(cb, url->query.data, url->query.length,
4587+
ctx, status);
4588+
}
4589+
4590+
if (!exclude_fragment && url->fragment.data != NULL) {
4591+
lexbor_serialize_write(cb, hs_str.data, hs_str.length,
4592+
ctx, status);
4593+
lexbor_serialize_write(cb, url->fragment.data, url->fragment.length,
4594+
ctx, status);
4595+
}
4596+
4597+
return LXB_STATUS_OK;
4598+
}
4599+
45264600
lxb_status_t
45274601
lxb_url_serialize_scheme(const lxb_url_t *url,
45284602
lexbor_serialize_cb_f cb, void *ctx)

Diff for: ext/dom/lexbor/lexbor/url/url.h

+21
Original file line numberDiff line numberDiff line change
@@ -404,6 +404,10 @@ LXB_API lxb_status_t
404404
lxb_url_serialize(const lxb_url_t *url, lexbor_serialize_cb_f cb, void *ctx,
405405
bool exclude_fragment);
406406

407+
LXB_API lxb_status_t
408+
lxb_url_serialize_unicode(lxb_unicode_idna_t *idna, const lxb_url_t *url, lexbor_serialize_cb_f cb, void *ctx,
409+
bool exclude_fragment);
410+
407411
LXB_API lxb_status_t
408412
lxb_url_serialize_scheme(const lxb_url_t *url,
409413
lexbor_serialize_cb_f cb, void *ctx);
@@ -462,6 +466,23 @@ lxb_url_serialize_fragment(const lxb_url_t *url,
462466
LXB_API lxb_url_t *
463467
lxb_url_clone(lexbor_mraw_t *mraw, lxb_url_t *url);
464468

469+
/*
470+
* Below are auxiliary functions.
471+
*/
472+
473+
typedef enum {
474+
LXB_URL_HOST_OPT_UNDEF = 0 << 0,
475+
LXB_URL_HOST_OPT_NOT_SPECIAL = 1 << 0,
476+
LXB_URL_HOST_OPT_DECODE = 1 << 1,
477+
LXB_URL_HOST_OPT_IDNA = 1 << 2
478+
}
479+
lxb_url_host_opt_t;
480+
481+
LXB_API lxb_status_t
482+
lxb_url_percent_decode(const lxb_char_t *data, const lxb_char_t *end,
483+
lexbor_str_t *str, lexbor_mraw_t *mraw,
484+
lxb_url_host_opt_t *opt);
485+
465486
/*
466487
* Inline functions.
467488
*/

Diff for: ext/filter/logical_filters.c

+6-6
Original file line numberDiff line numberDiff line change
@@ -619,14 +619,14 @@ void php_filter_validate_url(PHP_INPUT_FILTER_PARAM_DECL) /* {{{ */
619619
}
620620

621621
zval scheme;
622-
result = php_uri_get_scheme(internal_uri, &scheme);
622+
result = php_uri_get_scheme(internal_uri, URI_COMPONENT_READ_RAW, &scheme);
623623
if (result == FAILURE) {
624624
php_uri_free(internal_uri);
625625
RETURN_VALIDATION_FAILED
626626
}
627627

628628
zval host;
629-
result = php_uri_get_host(internal_uri, &host);
629+
result = php_uri_get_host(internal_uri, URI_COMPONENT_READ_RAW, &host);
630630
if (result == FAILURE) {
631631
zval_ptr_dtor(&scheme);
632632
php_uri_free(internal_uri);
@@ -668,7 +668,7 @@ void php_filter_validate_url(PHP_INPUT_FILTER_PARAM_DECL) /* {{{ */
668668
}
669669

670670
zval path;
671-
result = php_uri_get_path(internal_uri, &path);
671+
result = php_uri_get_path(internal_uri, URI_COMPONENT_READ_RAW, &path);
672672
if (result == FAILURE) {
673673
php_uri_free(internal_uri);
674674
zval_ptr_dtor(&scheme);
@@ -677,7 +677,7 @@ void php_filter_validate_url(PHP_INPUT_FILTER_PARAM_DECL) /* {{{ */
677677
}
678678

679679
zval query;
680-
result = php_uri_get_query(internal_uri, &query);
680+
result = php_uri_get_query(internal_uri, URI_COMPONENT_READ_RAW, &query);
681681
if (result == FAILURE) {
682682
php_uri_free(internal_uri);
683683
zval_ptr_dtor(&scheme);
@@ -706,14 +706,14 @@ void php_filter_validate_url(PHP_INPUT_FILTER_PARAM_DECL) /* {{{ */
706706
zval_ptr_dtor(&query);
707707

708708
zval user;
709-
result = php_uri_get_user(internal_uri, &user);
709+
result = php_uri_get_user(internal_uri, URI_COMPONENT_READ_RAW, &user);
710710
if (result == FAILURE) {
711711
php_uri_free(internal_uri);
712712
RETURN_VALIDATION_FAILED
713713
}
714714

715715
zval password;
716-
result = php_uri_get_password(internal_uri, &password);
716+
result = php_uri_get_password(internal_uri, URI_COMPONENT_READ_RAW, &password);
717717
if (result == FAILURE) {
718718
php_uri_free(internal_uri);
719719
zval_ptr_dtor(&user);

Diff for: ext/openssl/xp_ssl.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -2743,7 +2743,7 @@ static char *php_openssl_get_url_name(const char *resourcename,
27432743
}
27442744

27452745
zval host_zv;
2746-
zend_result result = php_uri_get_host(internal_uri, &host_zv);
2746+
zend_result result = php_uri_get_host(internal_uri, URI_COMPONENT_READ_RAW, &host_zv);
27472747
if (result == SUCCESS && Z_TYPE(host_zv) == IS_STRING) {
27482748
const char * host = Z_STRVAL(host_zv);
27492749
char * url_name = NULL;

0 commit comments

Comments
 (0)