mirror of
https://github.com/privatevoid-net/nix-super.git
synced 2024-11-23 06:26:15 +02:00
Fix url parsing for urls using file+
`file+https://example.org/test.mp4` should not be rejected with `unexpected authority`.
This commit is contained in:
parent
b911307d7a
commit
4d50995eff
2 changed files with 24 additions and 3 deletions
|
@ -99,6 +99,27 @@ namespace nix {
|
||||||
ASSERT_EQ(parsed, expected);
|
ASSERT_EQ(parsed, expected);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TEST(parseURL, parsesFilePlusHttpsUrl) {
|
||||||
|
auto s = "file+https://www.example.org/video.mp4";
|
||||||
|
auto parsed = parseURL(s);
|
||||||
|
|
||||||
|
ParsedURL expected {
|
||||||
|
.url = "file+https://www.example.org/video.mp4",
|
||||||
|
.base = "https://www.example.org/video.mp4",
|
||||||
|
.scheme = "file+https",
|
||||||
|
.authority = "www.example.org",
|
||||||
|
.path = "/video.mp4",
|
||||||
|
.query = (StringMap) { },
|
||||||
|
.fragment = "",
|
||||||
|
};
|
||||||
|
|
||||||
|
ASSERT_EQ(parsed, expected);
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST(parseURL, rejectsAuthorityInUrlsWithFileTransportation) {
|
||||||
|
auto s = "file://www.example.org/video.mp4";
|
||||||
|
ASSERT_THROW(parseURL(s), Error);
|
||||||
|
}
|
||||||
|
|
||||||
TEST(parseURL, parseIPv4Address) {
|
TEST(parseURL, parseIPv4Address) {
|
||||||
auto s = "http://127.0.0.1:8080/file.tar.gz?download=fast&when=now#hello";
|
auto s = "http://127.0.0.1:8080/file.tar.gz?download=fast&when=now#hello";
|
||||||
|
|
|
@ -30,13 +30,13 @@ ParsedURL parseURL(const std::string & url)
|
||||||
auto & query = match[6];
|
auto & query = match[6];
|
||||||
auto & fragment = match[7];
|
auto & fragment = match[7];
|
||||||
|
|
||||||
auto isFile = scheme.find("file") != std::string::npos;
|
auto transportIsFile = parseUrlScheme(scheme).transport == "file";
|
||||||
|
|
||||||
if (authority && *authority != "" && isFile)
|
if (authority && *authority != "" && transportIsFile)
|
||||||
throw BadURL("file:// URL '%s' has unexpected authority '%s'",
|
throw BadURL("file:// URL '%s' has unexpected authority '%s'",
|
||||||
url, *authority);
|
url, *authority);
|
||||||
|
|
||||||
if (isFile && path.empty())
|
if (transportIsFile && path.empty())
|
||||||
path = "/";
|
path = "/";
|
||||||
|
|
||||||
return ParsedURL{
|
return ParsedURL{
|
||||||
|
|
Loading…
Reference in a new issue