diff --git a/src/node_url.cc b/src/node_url.cc index b157c2ded1b5ae..e0a07326825e11 100644 --- a/src/node_url.cc +++ b/src/node_url.cc @@ -1426,7 +1426,7 @@ void URL::Parse(const char* input, const char ch = p < end ? p[0] : kEOL; bool special = (url->flags & URL_FLAGS_SPECIAL); bool cannot_be_base; - const bool special_back_slash = (special && ch == '\\'); + bool special_back_slash = (special && ch == '\\'); switch (state) { case kSchemeStart: @@ -1476,6 +1476,7 @@ void URL::Parse(const char* input, url->flags &= ~URL_FLAGS_SPECIAL; special = false; } + special_back_slash = (special && ch == '\\'); buffer.clear(); if (has_state_override) return; @@ -1520,6 +1521,7 @@ void URL::Parse(const char* input, url->flags &= ~URL_FLAGS_SPECIAL; special = false; } + special_back_slash = (special && ch == '\\'); if (base->flags & URL_FLAGS_HAS_PATH) { url->flags |= URL_FLAGS_HAS_PATH; url->path = base->path; @@ -1543,6 +1545,7 @@ void URL::Parse(const char* input, url->flags |= URL_FLAGS_SPECIAL; special = true; state = kFile; + special_back_slash = (special && ch == '\\'); continue; } break; @@ -1572,6 +1575,7 @@ void URL::Parse(const char* input, url->flags &= ~URL_FLAGS_SPECIAL; special = false; } + special_back_slash = (special && ch == '\\'); switch (ch) { case kEOL: if (base->flags & URL_FLAGS_HAS_USERNAME) { diff --git a/test/cctest/test_url.cc b/test/cctest/test_url.cc index 2e78b24a5e3424..ad729ab1c7ffbd 100644 --- a/test/cctest/test_url.cc +++ b/test/cctest/test_url.cc @@ -81,6 +81,52 @@ TEST_F(URLTest, Base3) { EXPECT_EQ(simple.path(), "/baz"); } +TEST_F(URLTest, Base4) { + const char* input = "\\x"; + const char* base = "http://example.org/foo/bar"; + + URL simple(input, strlen(input), base, strlen(base)); + + EXPECT_FALSE(simple.flags() & URL_FLAGS_FAILED); + EXPECT_EQ(simple.protocol(), "http:"); + EXPECT_EQ(simple.host(), "example.org"); + EXPECT_EQ(simple.path(), "/x"); +} + +TEST_F(URLTest, Base5) { + const char* input = "/x"; + const char* base = "http://example.org/foo/bar"; + + URL simple(input, strlen(input), base, strlen(base)); + + EXPECT_FALSE(simple.flags() & URL_FLAGS_FAILED); + EXPECT_EQ(simple.protocol(), "http:"); + EXPECT_EQ(simple.host(), "example.org"); + EXPECT_EQ(simple.path(), "/x"); +} + +TEST_F(URLTest, Base6) { + const char* input = "\\\\x"; + const char* base = "http://example.org/foo/bar"; + + URL simple(input, strlen(input), base, strlen(base)); + + EXPECT_FALSE(simple.flags() & URL_FLAGS_FAILED); + EXPECT_EQ(simple.protocol(), "http:"); + EXPECT_EQ(simple.host(), "x"); +} + +TEST_F(URLTest, Base7) { + const char* input = "//x"; + const char* base = "http://example.org/foo/bar"; + + URL simple(input, strlen(input), base, strlen(base)); + + EXPECT_FALSE(simple.flags() & URL_FLAGS_FAILED); + EXPECT_EQ(simple.protocol(), "http:"); + EXPECT_EQ(simple.host(), "x"); +} + TEST_F(URLTest, TruncatedAfterProtocol) { char input[2] = { 'q', ':' }; URL simple(input, sizeof(input));