Skip to content

Commit 755d98d

Browse files
giuspenGiuseppe Penone
and
Giuseppe Penone
authored
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 <[email protected]>
1 parent 98b4828 commit 755d98d

File tree

2 files changed

+40
-4
lines changed

2 files changed

+40
-4
lines changed

ixwebsocket/IXUrlParser.cpp

+6-4
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ namespace
180180
bHasUserName = true;
181181
break;
182182
}
183-
else if (*LocalString == '/')
183+
else if (*LocalString == '/' || *LocalString == '?')
184184
{
185185
// end of <host>:<port> specification
186186
bHasUserName = false;
@@ -242,7 +242,7 @@ namespace
242242
LocalString++;
243243
break;
244244
}
245-
else if (!bHasBracket && (*LocalString == ':' || *LocalString == '/'))
245+
else if (!bHasBracket && (*LocalString == ':' || *LocalString == '/' || *LocalString == '?'))
246246
{
247247
// port number is specified
248248
break;
@@ -280,12 +280,14 @@ namespace
280280
}
281281

282282
// skip '/'
283-
if (*CurrentString != '/')
283+
if (*CurrentString != '/' && *CurrentString != '?')
284284
{
285285
return clParseURL(LUrlParserError_NoSlash);
286286
}
287287

288-
CurrentString++;
288+
if (*CurrentString != '?') {
289+
CurrentString++;
290+
}
289291

290292
// parse the path
291293
LocalString = CurrentString;

test/IXUrlParserTest.cpp

+34
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,40 @@ namespace ix
8484
REQUIRE(port == 443); // default port for wss
8585
}
8686

87+
SECTION("wss://google.com/?arg=value")
88+
{
89+
std::string url = "wss://google.com/?arg=value&arg2=value2";
90+
std::string protocol, host, path, query;
91+
int port;
92+
bool res;
93+
94+
res = UrlParser::parse(url, protocol, host, path, query, port);
95+
96+
REQUIRE(res);
97+
REQUIRE(protocol == "wss");
98+
REQUIRE(host == "google.com");
99+
REQUIRE(path == "/?arg=value&arg2=value2");
100+
REQUIRE(query == "arg=value&arg2=value2");
101+
REQUIRE(port == 443); // default port for wss
102+
}
103+
104+
SECTION("wss://google.com?arg=value")
105+
{
106+
std::string url = "wss://google.com?arg=value&arg2=value2";
107+
std::string protocol, host, path, query;
108+
int port;
109+
bool res;
110+
111+
res = UrlParser::parse(url, protocol, host, path, query, port);
112+
113+
REQUIRE(res);
114+
REQUIRE(protocol == "wss");
115+
REQUIRE(host == "google.com");
116+
REQUIRE(path == "/?arg=value&arg2=value2");
117+
REQUIRE(query == "arg=value&arg2=value2");
118+
REQUIRE(port == 443); // default port for wss
119+
}
120+
87121
SECTION("real test")
88122
{
89123
std::string url =

0 commit comments

Comments
 (0)