Skip to content

Commit c32a637

Browse files
authored
fix issue 716 (#717)
1 parent 97a5fdd commit c32a637

File tree

3 files changed

+18
-2
lines changed

3 files changed

+18
-2
lines changed

include/ada/url-inl.h

+6-1
Original file line numberDiff line numberDiff line change
@@ -215,10 +215,15 @@ inline void url::copy_scheme(const ada::url &u) {
215215
ada_really_inline size_t url::parse_port(std::string_view view,
216216
bool check_trailing_content) noexcept {
217217
ada_log("parse_port('", view, "') ", view.size());
218+
if (!view.empty() && view[0] == '-') {
219+
ada_log("parse_port: view[0] == '0' && view.size() > 1");
220+
is_valid = false;
221+
return 0;
222+
}
218223
uint16_t parsed_port{};
219224
auto r = std::from_chars(view.data(), view.data() + view.size(), parsed_port);
220225
if (r.ec == std::errc::result_out_of_range) {
221-
ada_log("parse_port: std::errc::result_out_of_range");
226+
ada_log("parse_port: r.ec == std::errc::result_out_of_range");
222227
is_valid = false;
223228
return 0;
224229
}

include/ada/url_aggregator-inl.h

+6-1
Original file line numberDiff line numberDiff line change
@@ -853,10 +853,15 @@ inline bool url_aggregator::has_port() const noexcept {
853853
ada_really_inline size_t url_aggregator::parse_port(
854854
std::string_view view, bool check_trailing_content) noexcept {
855855
ada_log("url_aggregator::parse_port('", view, "') ", view.size());
856+
if (!view.empty() && view[0] == '-') {
857+
ada_log("parse_port: view[0] == '0' && view.size() > 1");
858+
is_valid = false;
859+
return 0;
860+
}
856861
uint16_t parsed_port{};
857862
auto r = std::from_chars(view.data(), view.data() + view.size(), parsed_port);
858863
if (r.ec == std::errc::result_out_of_range) {
859-
ada_log("parse_port: std::errc::result_out_of_range");
864+
ada_log("parse_port: r.ec == std::errc::result_out_of_range");
860865
is_valid = false;
861866
return 0;
862867
}

tests/basic_tests.cpp

+6
Original file line numberDiff line numberDiff line change
@@ -440,4 +440,10 @@ TYPED_TEST(basic_tests, path_setter_bug) {
440440
ASSERT_TRUE(base_url->set_pathname("//.."));
441441
ASSERT_TRUE(base_url->validate());
442442
SUCCEED();
443+
}
444+
445+
TYPED_TEST(basic_tests, negativeport) {
446+
auto url = ada::parse<TypeParam>("https://www.google.com");
447+
ASSERT_FALSE(url->set_port("-1"));
448+
SUCCEED();
443449
}

0 commit comments

Comments
 (0)