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
 (#1511)

Co-authored-by: Lalit Kumar Bhasin <[email protected]>
  • Loading branch information
wangzhen2271 and lalitb authored 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

1 comment on commit a77ec80

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Performance Alert ⚠️

Possible performance regression was detected for benchmark 'OpenTelemetry-cpp api Benchmark'.
Benchmark result of this commit is worse than the previous benchmark result exceeding threshold 2.

Benchmark suite Current: a77ec80 Previous: 0948054 Ratio
BM_CreateBaggageFrom180Entries 247996.17803152738 ns/iter 98595.91415247966 ns/iter 2.52
BM_SpinLockThrashing/1/process_time/real_time 1.065157102734855 ms/iter 0.21423309299021004 ms/iter 4.97
BM_SpinLockThrashing/2/process_time/real_time 2.761380672454834 ms/iter 0.3928844745342548 ms/iter 7.03
BM_ProcYieldSpinLockThrashing/1/process_time/real_time 0.5844977065807081 ms/iter 0.21169439160446235 ms/iter 2.76
BM_ProcYieldSpinLockThrashing/2/process_time/real_time 1.8398256405540134 ms/iter 0.4200924401995779 ms/iter 4.38
BM_NaiveSpinLockThrashing/1/process_time/real_time 1.1977060981418775 ms/iter 0.20873850779573944 ms/iter 5.74
BM_NaiveSpinLockThrashing/2/process_time/real_time 1.9404415611748222 ms/iter 0.4202314236197054 ms/iter 4.62
BM_ThreadYieldSpinLockThrashing/1/process_time/real_time 33.144426345825195 ms/iter 13.24160893758138 ms/iter 2.50

This comment was automatically generated by workflow using github-action-benchmark.

Please sign in to comment.