Skip to content

Commit cdfd207

Browse files
committed
Intermediate changes
commit_hash:d92446f14c476da0a2e64664e0a97455e4d5d32a
1 parent f6a7f46 commit cdfd207

File tree

1 file changed

+29
-6
lines changed

1 file changed

+29
-6
lines changed

library/cpp/neh/location.cpp

Lines changed: 29 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,38 @@
44

55
using namespace NNeh;
66

7+
namespace {
8+
bool IsHttps(TStringBuf scheme) {
9+
return TStringBuf("https") == scheme || TStringBuf("fulls") == scheme || TStringBuf("posts") == scheme;
10+
}
11+
12+
bool SplitUserInfo(TStringBuf& path, TStringBuf& userInfo, bool mayHaveSpecificUserInfo) {
13+
const size_t pos = path.find_first_of(mayHaveSpecificUserInfo ? TStringBuf("?@") : TStringBuf("?@/"));
14+
15+
if (TStringBuf::npos != pos && '@' == path[pos]) {
16+
if (mayHaveSpecificUserInfo) {
17+
if (!(path.StartsWith("cert=") || path.StartsWith("key="))) {
18+
return false;
19+
}
20+
}
21+
22+
path.SplitAt(pos, userInfo, path);
23+
path.Skip(1);
24+
}
25+
26+
return true;
27+
}
28+
}
29+
730
TParsedLocation::TParsedLocation(TStringBuf path) {
831
path.Split(':', Scheme, path);
932
path.Skip(2);
1033

11-
const size_t pos = path.find_first_of(TStringBuf("?@"));
12-
13-
if (TStringBuf::npos != pos && '@' == path[pos]) {
14-
path.SplitAt(pos, UserInfo, path);
15-
path.Skip(1);
34+
// try to handle both https://cert=./path_to_cert@host:port/... (userinfo is "cert=./path_to_cert")
35+
// and http[s]://host:port/@zzz (userinfo is empty, host is host, not zzz
36+
// see SEARCH-14238
37+
if (!SplitUserInfo(path, UserInfo, IsHttps(Scheme))) {
38+
SplitUserInfo(path, UserInfo, false);
1639
}
1740

1841
auto checkRange = [](size_t b, size_t e){
@@ -43,7 +66,7 @@ TParsedLocation::TParsedLocation(TStringBuf path) {
4366

4467
ui16 TParsedLocation::GetPort() const {
4568
if (!Port) {
46-
return TStringBuf("https") == Scheme || TStringBuf("fulls") == Scheme || TStringBuf("posts") == Scheme ? 443 : 80;
69+
return IsHttps(Scheme) ? 443 : 80;
4770
}
4871

4972
return FromString<ui16>(Port);

0 commit comments

Comments
 (0)