mirror of
https://github.com/NixOS/nix.git
synced 2025-11-10 12:36:01 +01:00
libutil: Fix handling of unescaped spaces, quotes and shevrons in queries and fragments
Turns out we didn't have tests for some of the important behavior introduced
for flake reference fragments and url queries [1]. This is rather important
and is relied upon by existing tooling. This fixes up these exact cases before
handing off the URL to the Boost.URL parser.
To the best of my knowledge this implements the same behavior as prior regex-based
parser did [2]:
> fragmentRegex = "(?:" + pcharRegex + "|[/? \"^])*";
> queryRegex = "(?:" + pcharRegex + "|[/? \"])*";
[1]: 9c0a09f09f
[2]: https://github.com/NixOS/nix/blob/2.30.2/src/libutil/include/nix/util/url-parts.hh
This commit is contained in:
parent
0fd9ef0cf3
commit
dc1b2012af
4 changed files with 96 additions and 33 deletions
|
|
@ -74,6 +74,20 @@ TEST(parseFlakeRef, GitArchiveInput)
|
|||
auto flakeref = parseFlakeRef(fetchSettings, s);
|
||||
ASSERT_EQ(flakeref.to_string(), "github:foo/bar/branch%23");
|
||||
}
|
||||
|
||||
{
|
||||
auto s = "github:foo/bar?ref=branch#\"name.with.dot\""; // unescaped quotes `"`
|
||||
auto [flakeref, fragment] = parseFlakeRefWithFragment(fetchSettings, s);
|
||||
ASSERT_EQ(fragment, "\"name.with.dot\"");
|
||||
ASSERT_EQ(flakeref.to_string(), "github:foo/bar/branch");
|
||||
}
|
||||
|
||||
{
|
||||
auto s = "github:foo/bar#\"name.with.dot\""; // unescaped quotes `"`
|
||||
auto [flakeref, fragment] = parseFlakeRefWithFragment(fetchSettings, s);
|
||||
ASSERT_EQ(fragment, "\"name.with.dot\"");
|
||||
ASSERT_EQ(flakeref.to_string(), "github:foo/bar");
|
||||
}
|
||||
}
|
||||
|
||||
TEST(to_string, doesntReencodeUrl)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue