Skip to content

Commit

Permalink
Support URLs with no slash before the question mark (#507)
Browse files Browse the repository at this point in the history
* Support Url No Slash Before Question Mark

* Support Url No Slash Before Question Mark

* unit test fix

---------

Co-authored-by: Giuseppe Penone <[email protected]>
  • Loading branch information
giuspen and Giuseppe Penone authored Mar 19, 2024
1 parent 98b4828 commit 755d98d
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 4 deletions.
10 changes: 6 additions & 4 deletions ixwebsocket/IXUrlParser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ namespace
bHasUserName = true;
break;
}
else if (*LocalString == '/')
else if (*LocalString == '/' || *LocalString == '?')
{
// end of <host>:<port> specification
bHasUserName = false;
Expand Down Expand Up @@ -242,7 +242,7 @@ namespace
LocalString++;
break;
}
else if (!bHasBracket && (*LocalString == ':' || *LocalString == '/'))
else if (!bHasBracket && (*LocalString == ':' || *LocalString == '/' || *LocalString == '?'))
{
// port number is specified
break;
Expand Down Expand Up @@ -280,12 +280,14 @@ namespace
}

// skip '/'
if (*CurrentString != '/')
if (*CurrentString != '/' && *CurrentString != '?')
{
return clParseURL(LUrlParserError_NoSlash);
}

CurrentString++;
if (*CurrentString != '?') {
CurrentString++;
}

// parse the path
LocalString = CurrentString;
Expand Down
34 changes: 34 additions & 0 deletions test/IXUrlParserTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 =
Expand Down

0 comments on commit 755d98d

Please sign in to comment.