Skip to content

Commit 428df97

Browse files
committed
fix: urlPaser will incorrect parsing url like http://abc.com/xxx@xxx/a/b
1 parent beba414 commit 428df97

File tree

2 files changed

+16
-4
lines changed

2 files changed

+16
-4
lines changed

ext/include/opentelemetry/ext/http/common/url_parser.h

+9-4
Original file line numberDiff line numberDiff line change
@@ -52,11 +52,16 @@ class UrlParser
5252
}
5353

5454
// credentials
55-
pos = url_.find_first_of("@", cpos);
56-
if (pos != std::string::npos)
55+
size_t pos1 = url_.find_first_of("@", cpos);
56+
size_t pos2 = url_.find_first_of("/", cpos);
57+
if (pos1 != std::string::npos)
5758
{
5859
// TODO - handle credentials
59-
cpos = pos + 1;
60+
if (pos2 == std::string::npos || pos1 < pos2)
61+
{
62+
pos = pos1;
63+
cpos = pos1 + 1;
64+
}
6065
}
6166
pos = url_.find_first_of(":", cpos);
6267
bool is_port = false;
@@ -129,4 +134,4 @@ class UrlParser
129134

130135
} // namespace http
131136
} // namespace ext
132-
OPENTELEMETRY_END_NAMESPACE
137+
OPENTELEMETRY_END_NAMESPACE

ext/test/http/url_parser_test.cc

+7
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,13 @@ TEST(UrlParserTests, BasicTests)
113113
{"path", "/path1/path2"},
114114
{"query", "q1=a1&q2=a2"},
115115
{"success", "true"}}},
116+
{"http://www.abc.com/path1@bbb/path2?q1=a1&q2=a2",
117+
{{"host", "www.abc.com"},
118+
{"port", "80"},
119+
{"scheme", "http"},
120+
{"path", "/path1@bbb/path2"},
121+
{"query", "q1=a1&q2=a2"},
122+
{"success", "true"}}},
116123

117124
};
118125
for (auto &url_map : urls_map)

0 commit comments

Comments
 (0)