Skip to content

Commit 2a74a11

Browse files
committed
fix: support having 0 as the port number
1 parent 7e3fcf9 commit 2a74a11

File tree

2 files changed

+11
-2
lines changed

2 files changed

+11
-2
lines changed

include/ada/url-inl.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,11 @@ ada_really_inline size_t url::parse_port(std::string_view view,
230230
}
231231
ada_log("parse_port: is_valid = ", is_valid);
232232
if (is_valid) {
233-
port = (r.ec == std::errc() && scheme_default_port() != parsed_port)
233+
// scheme_default_port can return 0, and we should allow 0 as a base port.
234+
auto default_port = scheme_default_port();
235+
bool is_port_valid = (default_port == 0 && parsed_port == 0) ||
236+
(default_port != parsed_port);
237+
port = (r.ec == std::errc() && is_port_valid)
234238
? std::optional<uint16_t>(parsed_port)
235239
: std::nullopt;
236240
}

include/ada/url_aggregator-inl.h

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -854,7 +854,12 @@ ada_really_inline size_t url_aggregator::parse_port(
854854
}
855855
ada_log("parse_port: is_valid = ", is_valid);
856856
if (is_valid) {
857-
if (r.ec == std::errc() && scheme_default_port() != parsed_port) {
857+
ada_log("parse_port", r.ec == std::errc());
858+
// scheme_default_port can return 0, and we should allow 0 as a base port.
859+
auto default_port = scheme_default_port();
860+
bool is_port_valid = (default_port == 0 && parsed_port == 0) ||
861+
(default_port != parsed_port);
862+
if (r.ec == std::errc() && is_port_valid) {
858863
update_base_port(parsed_port);
859864
} else {
860865
clear_port();

0 commit comments

Comments
 (0)