Skip to content

Commit 007c92a

Browse files
committed
Strip query string before parsing target (origin).
1 parent 8707bc2 commit 007c92a

File tree

2 files changed

+5
-4
lines changed

2 files changed

+5
-4
lines changed

src/parse/target.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,8 @@ static hash_cptr to_hash(const std::string_view& token) NOEXCEPT
4848

4949
code parse_target(request_t& out, const std::string_view& path) NOEXCEPT
5050
{
51-
if (path.empty())
51+
const auto clean = split(path, "?", false, false).front();
52+
if (clean.empty())
5253
return error::empty_path;
5354

5455
// Avoid conflict with node type.
@@ -65,7 +66,7 @@ code parse_target(request_t& out, const std::string_view& path) NOEXCEPT
6566

6667
auto& method = out.method;
6768
auto& params = std::get<object_t>(out.params.value());
68-
const auto segments = split(path, "/", false, true);
69+
const auto segments = split(clean, "/", false, true);
6970
BC_ASSERT(!segments.empty());
7071

7172
size_t segment{};

test/parse/target.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ using object_t = network::rpc::object_t;
2929
BOOST_AUTO_TEST_CASE(parse__parse_target__empty_path__empty_path)
3030
{
3131
request_t out{};
32-
BOOST_REQUIRE_EQUAL(parse_target(out, ""), node::error::empty_path);
32+
BOOST_REQUIRE_EQUAL(parse_target(out, "?foo=bar"), node::error::empty_path);
3333
}
3434

3535
BOOST_AUTO_TEST_CASE(parse__parse_target__missing_version__missing_version)
@@ -67,7 +67,7 @@ BOOST_AUTO_TEST_CASE(parse__parse_target__invalid_target__invalid_target)
6767

6868
BOOST_AUTO_TEST_CASE(parse__parse_target__block_hash_valid__expected)
6969
{
70-
const std::string path = "//v42//block//hash//0000000000000000000000000000000000000000000000000000000000000042//";
70+
const std::string path = "//v42//block//hash//0000000000000000000000000000000000000000000000000000000000000042//?foo=bar";
7171

7272
request_t request{};
7373
BOOST_REQUIRE(!parse_target(request, path));

0 commit comments

Comments
 (0)