Skip to content

Commit 138efa6

Browse files
committed
[core] Support paths starting with two slashes
Fixes ROOT-5430
1 parent 77f5d80 commit 138efa6

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

core/base/src/TUrl.cxx

+8-1
Original file line numberDiff line numberDiff line change
@@ -131,13 +131,20 @@ void TUrl::SetUrl(const char *url, Bool_t defaultIsFile)
131131
fHostFQ = "";
132132

133133
// if url starts with a / consider it as a file url
134-
if (url[0] == '/')
134+
if (url[0] == '/') {
135135
defaultIsFile = kTRUE;
136+
// ROOT-5430: if url starts with two slashes but
137+
// not three slashes, just remove the first of them
138+
if (strlen(url) > 2 && url[1] == '/' && url[2] != '/') {
139+
url = &url[1];
140+
}
141+
}
136142

137143
// Find protocol
138144
char *s, sav;
139145

140146
TString surl = url;
147+
141148
char *u, *u0 = Strip(defaultIsFile && surl.EndsWith(":/") ? TString(surl(0,surl.Length()-2)).Data() : url);
142149
tryfile:
143150
u = u0;

core/base/test/TUrlTest.cxx

+6
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,10 @@ TEST(TUrl, FilePath)
1212
//https://its.cern.ch/jira/browse/ROOT-5820
1313
TUrl u2("/tmp/a.root:/", kTRUE); // TFile.GetPath() returns a trailing :/
1414
EXPECT_TRUE(u2.IsValid());
15+
16+
// ROOT-5430
17+
const char * ref_5430 = "file:///tmp/t.root";
18+
EXPECT_STREQ(TUrl("/tmp/t.root").GetUrl(), ref_5430);
19+
EXPECT_STREQ(TUrl("//tmp/t.root").GetUrl(), ref_5430);
20+
EXPECT_STREQ(TUrl("///tmp/t.root").GetUrl(), ref_5430);
1521
}

0 commit comments

Comments
 (0)