1
1
Fork 0
mirror of https://github.com/NixOS/nix.git synced 2025-12-04 16:10:59 +01:00

libfetchers: Remove badGitRefRegex and use libgit2 for reference validation

Fixes usage of `#` symbol in the reference name.
This also seems to identify several deficiencies in the libgit2 refname
validation code wrt to DEL symbol and a singular `@` symbol [1].

[1]: https://git-scm.com/docs/git-check-ref-format#_description
This commit is contained in:
Sergei Zimmerman 2025-08-11 01:00:21 +03:00
parent 0b7f7e4b03
commit e8e9376a7b
No known key found for this signature in database
10 changed files with 154 additions and 19 deletions

View file

@ -173,4 +173,58 @@ TEST_F(GitUtilsTest, peel_reference)
git_repository_free(rawRepo);
}
TEST(GitUtils, isLegalRefName)
{
ASSERT_TRUE(isLegalRefName("foox"));
ASSERT_TRUE(isLegalRefName("1337"));
ASSERT_TRUE(isLegalRefName("foo.baz"));
ASSERT_TRUE(isLegalRefName("foo/bar/baz"));
ASSERT_TRUE(isLegalRefName("foo./bar"));
ASSERT_TRUE(isLegalRefName("heads/foo@bar"));
ASSERT_TRUE(isLegalRefName("heads/fu\303\237"));
ASSERT_TRUE(isLegalRefName("foo-bar-baz"));
ASSERT_TRUE(isLegalRefName("branch#"));
ASSERT_TRUE(isLegalRefName("$1"));
ASSERT_TRUE(isLegalRefName("foo.locke"));
ASSERT_FALSE(isLegalRefName("refs///heads/foo"));
ASSERT_FALSE(isLegalRefName("heads/foo/"));
ASSERT_FALSE(isLegalRefName("///heads/foo"));
ASSERT_FALSE(isLegalRefName(".foo"));
ASSERT_FALSE(isLegalRefName("./foo"));
ASSERT_FALSE(isLegalRefName("./foo/bar"));
ASSERT_FALSE(isLegalRefName("foo/./bar"));
ASSERT_FALSE(isLegalRefName("foo/bar/."));
ASSERT_FALSE(isLegalRefName("foo bar"));
ASSERT_FALSE(isLegalRefName("foo?bar"));
ASSERT_FALSE(isLegalRefName("foo^bar"));
ASSERT_FALSE(isLegalRefName("foo~bar"));
ASSERT_FALSE(isLegalRefName("foo:bar"));
ASSERT_FALSE(isLegalRefName("foo[bar"));
ASSERT_FALSE(isLegalRefName("foo/bar/."));
ASSERT_FALSE(isLegalRefName(".refs/foo"));
ASSERT_FALSE(isLegalRefName("refs/heads/foo."));
ASSERT_FALSE(isLegalRefName("heads/foo..bar"));
ASSERT_FALSE(isLegalRefName("heads/foo?bar"));
ASSERT_FALSE(isLegalRefName("heads/foo.lock"));
ASSERT_FALSE(isLegalRefName("heads///foo.lock"));
ASSERT_FALSE(isLegalRefName("foo.lock/bar"));
ASSERT_FALSE(isLegalRefName("foo.lock///bar"));
ASSERT_FALSE(isLegalRefName("heads/v@{ation"));
ASSERT_FALSE(isLegalRefName("heads/foo\bar"));
ASSERT_FALSE(isLegalRefName("@"));
ASSERT_FALSE(isLegalRefName("\37"));
ASSERT_FALSE(isLegalRefName("\177"));
ASSERT_FALSE(isLegalRefName("foo/*"));
ASSERT_FALSE(isLegalRefName("*/foo"));
ASSERT_FALSE(isLegalRefName("foo/*/bar"));
ASSERT_FALSE(isLegalRefName("*"));
ASSERT_FALSE(isLegalRefName("foo/*/*"));
ASSERT_FALSE(isLegalRefName("*/foo/*"));
ASSERT_FALSE(isLegalRefName("/foo"));
ASSERT_FALSE(isLegalRefName(""));
}
} // namespace nix