From de66c68ddc2e21f464b6f42c606f6ad817fe9541 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rimas=20Misevi=C4=8Dius?= Date: Wed, 11 Dec 2024 20:01:23 +0200 Subject: [PATCH] Fix: set_port should return false if input does not start with a digit --- include/upa/url.h | 9 +++++---- test/test-url-setters.cpp | 4 ++++ 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/include/upa/url.h b/include/upa/url.h index 88d08c9..5202089 100644 --- a/include/upa/url.h +++ b/include/upa/url.h @@ -1982,10 +1982,11 @@ inline validation_errc url_parser::url_parse(url_serializer& urls, const CharT* urls.clear_part(url::PORT); } } - } - // 2.2. If state override is given, then return - if (state_override) - return validation_errc::ok; + // 2.2. If state override is given, then return + if (state_override) + return validation_errc::ok; + } else if (state_override) + return validation_errc::ignored; state = path_start_state; pointer = end_of_digits; } else { diff --git a/test/test-url-setters.cpp b/test/test-url-setters.cpp index 50ac64c..8fb8eec 100644 --- a/test/test-url-setters.cpp +++ b/test/test-url-setters.cpp @@ -49,6 +49,10 @@ TEST_CASE("Test setters with special URL's") { CHECK_EQ(url.host(), "example.net:88"); CHECK_EQ(url.port_int(), 88); + CHECK(url.port("90=")); + CHECK_FALSE(url.port("abc")); + CHECK_EQ(url.port_int(), 90); + CHECK(url.port("")); CHECK_EQ(url.host(), "example.net");