From 755d98d918ea8efd559d0cc8e4d111489b807ff5 Mon Sep 17 00:00:00 2001 From: Giuseppe Penone Date: Tue, 19 Mar 2024 05:26:45 +0000 Subject: [PATCH] Support URLs with no slash before the question mark (#507) * Support Url No Slash Before Question Mark * Support Url No Slash Before Question Mark * unit test fix --------- Co-authored-by: Giuseppe Penone --- ixwebsocket/IXUrlParser.cpp | 10 ++++++---- test/IXUrlParserTest.cpp | 34 ++++++++++++++++++++++++++++++++++ 2 files changed, 40 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..dd2786dc 100644 --- a/test/IXUrlParserTest.cpp +++ b/test/IXUrlParserTest.cpp @@ -84,6 +84,40 @@ 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"; + 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 =