Skip to content

Commit bc4a925

Browse files
committed
Windows local file path resolve fix
1 parent e884eac commit bc4a925

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

src/url.cpp

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#include <algorithm>
22
#include <string>
3+
#include <cstring>
34
#include <iterator>
45
#include <unordered_map>
56
#include <unordered_set>
@@ -266,6 +267,15 @@ namespace Url
266267
}
267268
}
268269

270+
// Windows file path
271+
if ((strncmp(scheme_.c_str(), "file", 4) == 0) &&
272+
(static_cast<int>(url.length() - position) >= 2
273+
&& url[position] == '/'
274+
&& url[position + 2] == ':'))
275+
{
276+
position += 1;
277+
}
278+
269279
if (position != std::string::npos)
270280
{
271281
path_.assign(url, position, std::string::npos);
@@ -443,7 +453,8 @@ namespace Url
443453
}
444454
else
445455
{
446-
if (!host_.empty() && path_[0] != '/')
456+
if ((!host_.empty() && path_[0] != '/') ||
457+
(host_.empty() && path_[0] != '/' && path_[1] == ':'))
447458
{
448459
result.append(1, '/');
449460
}

0 commit comments

Comments
 (0)