diff --git a/NEWS b/NEWS index 0c80ffefb1b2..403476a95241 100644 --- a/NEWS +++ b/NEWS @@ -96,6 +96,7 @@ PHP NEWS file fails after it was already truncated. (Ilia Alshanetsky) - Standard: + . Fixed URL rewriting dropping an explicit port 0. (Ilia Alshanetsky) . Fixed chown() and lchown() failing to resolve user names in ZTS builds when getpwnam_r() needs a larger buffer. (Ilia Alshanetsky) . Fixed password_get_info() and password_needs_rehash() accepting malformed diff --git a/ext/standard/tests/general_functions/output_add_rewrite_var_port_zero.phpt b/ext/standard/tests/general_functions/output_add_rewrite_var_port_zero.phpt new file mode 100644 index 000000000000..1263bc8bcd8f --- /dev/null +++ b/ext/standard/tests/general_functions/output_add_rewrite_var_port_zero.phpt @@ -0,0 +1,26 @@ +--TEST-- +output_add_rewrite_var() preserves an explicit port zero +--INI-- +url_rewriter.tags="a=href,form=action" +url_rewriter.hosts="php.net" +--FILE-- + +no port +zero port +nonzero port +
no port
+
zero port
+
nonzero port
+ +--EXPECT-- +no port +zero port +nonzero port +
no port
+
zero port
+
nonzero port
diff --git a/ext/standard/url_scanner_ex.re b/ext/standard/url_scanner_ex.re index 61b55a6ef282..364f89dc5a7d 100644 --- a/ext/standard/url_scanner_ex.re +++ b/ext/standard/url_scanner_ex.re @@ -191,9 +191,10 @@ alphadash = ([a-zA-Z] | "-"); static inline void append_modified_url(smart_str *url, smart_str *dest, smart_str *url_app, const char *separator, int type) { php_url *url_parts; + bool has_port; smart_str_0(url); /* FIXME: Bug #70480 php_url_parse_ex() crashes by processing chars exceed len */ - url_parts = php_url_parse_ex(ZSTR_VAL(url->s), ZSTR_LEN(url->s)); + url_parts = php_url_parse_ex2(ZSTR_VAL(url->s), ZSTR_LEN(url->s), &has_port); /* Ignore malformed URLs */ if (!url_parts) { @@ -261,7 +262,7 @@ static inline void append_modified_url(smart_str *url, smart_str *dest, smart_st if (url_parts->host) { smart_str_appends(dest, ZSTR_VAL(url_parts->host)); } - if (url_parts->port) { + if (has_port) { smart_str_appendc(dest, ':'); smart_str_append_unsigned(dest, (long)url_parts->port); }