Skip to content

Commit

Permalink
fix: urlPaser will incorrect parsing url like http://abc.com/xxx@xxx/a/b
Browse files Browse the repository at this point in the history
 (open-telemetry#1511)

Co-authored-by: Lalit Kumar Bhasin <labhas@microsoft.com>
  • Loading branch information
wangzhen2271 and lalitb committed Jul 22, 2022
1 parent 0948054 commit a77ec80
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 4 deletions.
13 changes: 9 additions & 4 deletions ext/include/opentelemetry/ext/http/common/url_parser.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,16 @@ class UrlParser
}

// credentials
pos = url_.find_first_of("@", cpos);
if (pos != std::string::npos)
size_t pos1 = url_.find_first_of("@", cpos);
size_t pos2 = url_.find_first_of("/", cpos);
if (pos1 != std::string::npos)
{
// TODO - handle credentials
cpos = pos + 1;
if (pos2 == std::string::npos || pos1 < pos2)
{
pos = pos1;
cpos = pos1 + 1;
}
}
pos = url_.find_first_of(":", cpos);
bool is_port = false;
Expand Down Expand Up @@ -129,4 +134,4 @@ class UrlParser

} // namespace http
} // namespace ext
OPENTELEMETRY_END_NAMESPACE
OPENTELEMETRY_END_NAMESPACE
7 changes: 7 additions & 0 deletions ext/test/http/url_parser_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,13 @@ TEST(UrlParserTests, BasicTests)
{"path", "/path1/path2"},
{"query", "q1=a1&q2=a2"},
{"success", "true"}}},
{"http://www.abc.com/path1@bbb/path2?q1=a1&q2=a2",
{{"host", "www.abc.com"},
{"port", "80"},
{"scheme", "http"},
{"path", "/path1@bbb/path2"},
{"query", "q1=a1&q2=a2"},
{"success", "true"}}},

};
for (auto &url_map : urls_map)
Expand Down

0 comments on commit a77ec80

Please sign in to comment.