From 02da74507f2b3dee1f834bb35db1d5f4b1790f15 Mon Sep 17 00:00:00 2001 From: Giuseppe Penone Date: Fri, 8 Mar 2024 12:30:55 +0000 Subject: [PATCH 1/3] Support Url No Slash Before Question Mark --- ixwebsocket/IXUrlParser.cpp | 10 ++++++---- test/IXUrlParserTest.cpp | 17 +++++++++++++++++ 2 files changed, 23 insertions(+), 4 deletions(-) diff --git a/ixwebsocket/IXUrlParser.cpp b/ixwebsocket/IXUrlParser.cpp index aa1ef408..c5cdb57b 100644 --- a/ixwebsocket/IXUrlParser.cpp +++ b/ixwebsocket/IXUrlParser.cpp @@ -180,7 +180,7 @@ namespace bHasUserName = true; break; } - else if (*LocalString == '/') + else if (*LocalString == '/' || *LocalString == '?') { // end of : specification bHasUserName = false; @@ -242,7 +242,7 @@ namespace LocalString++; break; } - else if (!bHasBracket && (*LocalString == ':' || *LocalString == '/')) + else if (!bHasBracket && (*LocalString == ':' || *LocalString == '/' || *LocalString == '?')) { // port number is specified break; @@ -280,12 +280,14 @@ namespace } // skip '/' - if (*CurrentString != '/') + if (*CurrentString != '/' && *CurrentString != '?') { return clParseURL(LUrlParserError_NoSlash); } - CurrentString++; + if (*CurrentString != '?') { + CurrentString++; + } // parse the path LocalString = CurrentString; diff --git a/test/IXUrlParserTest.cpp b/test/IXUrlParserTest.cpp index cee3f3bf..5e101684 100644 --- a/test/IXUrlParserTest.cpp +++ b/test/IXUrlParserTest.cpp @@ -84,6 +84,23 @@ namespace ix REQUIRE(port == 443); // default port for wss } + SECTION("wss://google.com?arg=value") + { + std::string url = "wss://google.com?arg=value&arg2=value2"; + std::string protocol, host, path, query; + int port; + bool res; + + res = UrlParser::parse(url, protocol, host, path, query, port); + + REQUIRE(res); + REQUIRE(protocol == "wss"); + REQUIRE(host == "google.com"); + REQUIRE(path == "?arg=value&arg2=value2"); + REQUIRE(query == "arg=value&arg2=value2"); + REQUIRE(port == 443); // default port for wss + } + SECTION("real test") { std::string url = From 101947adf622ce46135795a790180c4ffbea3cee Mon Sep 17 00:00:00 2001 From: Giuseppe Penone Date: Fri, 8 Mar 2024 13:26:24 +0000 Subject: [PATCH 2/3] Support Url No Slash Before Question Mark --- test/IXUrlParserTest.cpp | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/test/IXUrlParserTest.cpp b/test/IXUrlParserTest.cpp index 5e101684..b76d0428 100644 --- a/test/IXUrlParserTest.cpp +++ b/test/IXUrlParserTest.cpp @@ -84,6 +84,23 @@ namespace ix REQUIRE(port == 443); // default port for wss } + SECTION("wss://google.com/?arg=value") + { + std::string url = "wss://google.com?arg=value&arg2=value2"; + std::string protocol, host, path, query; + int port; + bool res; + + res = UrlParser::parse(url, protocol, host, path, query, port); + + REQUIRE(res); + REQUIRE(protocol == "wss"); + REQUIRE(host == "google.com"); + REQUIRE(path == "/?arg=value&arg2=value2"); + REQUIRE(query == "arg=value&arg2=value2"); + REQUIRE(port == 443); // default port for wss + } + SECTION("wss://google.com?arg=value") { std::string url = "wss://google.com?arg=value&arg2=value2"; @@ -96,7 +113,7 @@ namespace ix REQUIRE(res); REQUIRE(protocol == "wss"); REQUIRE(host == "google.com"); - REQUIRE(path == "?arg=value&arg2=value2"); + REQUIRE(path == "/?arg=value&arg2=value2"); REQUIRE(query == "arg=value&arg2=value2"); REQUIRE(port == 443); // default port for wss } From 17b0d6d307cf42f161cfd697dfb8bdf3639b5653 Mon Sep 17 00:00:00 2001 From: Giuseppe Penone Date: Fri, 8 Mar 2024 13:30:06 +0000 Subject: [PATCH 3/3] unit test fix --- test/IXUrlParserTest.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/IXUrlParserTest.cpp b/test/IXUrlParserTest.cpp index b76d0428..dd2786dc 100644 --- a/test/IXUrlParserTest.cpp +++ b/test/IXUrlParserTest.cpp @@ -86,7 +86,7 @@ namespace ix SECTION("wss://google.com/?arg=value") { - std::string url = "wss://google.com?arg=value&arg2=value2"; + std::string url = "wss://google.com/?arg=value&arg2=value2"; std::string protocol, host, path, query; int port; bool res;