diff --git a/src/network_utilities.cpp b/src/network_utilities.cpp index d83c2c5048..9ebf52b9b7 100644 --- a/src/network_utilities.cpp +++ b/src/network_utilities.cpp @@ -136,11 +136,9 @@ std::string lookup_ws_close_status_string(uint16_t code) { bool websocketpp::ws_uri::parse(const std::string& uri) { boost::cmatch what; - static const boost::regex expression("(ws|wss)://([^/:\\[]+|\\[[0-9:]+\\])(:\\d{1,5})?(/.*)?"); + static const boost::regex expression("(ws|wss)://([^/:\\[]+|\\[[0-9:]+\\])(:\\d{1,5})?(/[^#]*)?"); - // TODO: finish section 3 conformance: - // - forbid # character (fragment is meaningless to websocket - // - maybe split out query portion into path/query? + // TODO: should this split resource into path/query? if (boost::regex_match(uri.c_str(), what, expression)) { if (what[1] == "wss") { diff --git a/src/network_utilities.hpp b/src/network_utilities.hpp index d91ec2face..a5871219e8 100644 --- a/src/network_utilities.hpp +++ b/src/network_utilities.hpp @@ -54,7 +54,6 @@ struct ws_uri { std::string host; uint16_t port; std::string resource; - std::string query; }; } diff --git a/test/basic/parsing.cpp b/test/basic/parsing.cpp index 6f93561f7c..6c74c2d7a9 100644 --- a/test/basic/parsing.cpp +++ b/test/basic/parsing.cpp @@ -145,3 +145,22 @@ BOOST_AUTO_TEST_CASE( uri_invalid_gt_16_bit_port ) { BOOST_CHECK( uri.parse("wss:/localhost:70000/chat") == false); } + +// Invalid URI includes uri fragment +BOOST_AUTO_TEST_CASE( uri_invalid_fragment ) { + websocketpp::ws_uri uri; + + BOOST_CHECK( uri.parse("wss:/localhost:70000/chat#foo") == false); +} + +// Valid URI complicated resource path with query +BOOST_AUTO_TEST_CASE( uri_valid_4 ) { + websocketpp::ws_uri uri; + + BOOST_CHECK( uri.parse("wss://localhost:9000/chat/foo/bar?foo=bar") == true); + BOOST_CHECK( uri.secure == true ); + BOOST_CHECK( uri.host == "localhost"); + BOOST_CHECK( uri.port == 9000 ); + BOOST_CHECK( uri.resource == "/chat/foo/bar?foo=bar" ); +} +