fix(tvix/nix-compat): drop first character period check

Suggested in https://cl.tvl.fyi/c/depot/+/9108/5, but this disallows
adding a .gitignore file to the store.

Remove the check, and add a testcase.

Change-Id: Ieb78c417934756b2dbeb493040fe79726d1b9079
Reviewed-on: https://cl.tvl.fyi/c/depot/+/9447
Tested-by: BuildkiteCI
Reviewed-by: raitobezarius <tvl@lahfa.xyz>
Autosubmit: flokli <flokli@flokli.de>
This commit is contained in:
Florian Klink 2023-09-23 12:32:20 +03:00 committed by flokli
parent 4f13b52047
commit dfb3d30d45

View file

@ -153,7 +153,7 @@ impl StorePath {
}
}
/// Checks a given &[u8] to match the restrictions for store path names, and
/// Checks a given &[u8] to match the restrictions for [StorePath::name], and
/// returns the name as string if successful.
pub(crate) fn validate_name(s: &[u8]) -> Result<String, Error> {
// Empty names are not allowed.
@ -161,11 +161,6 @@ pub(crate) fn validate_name(s: &[u8]) -> Result<String, Error> {
return Err(Error::InvalidLength());
}
// First character cannot be a period
if s[0] == b'.' {
return Err(Error::InvalidName(s.to_vec(), 0));
}
for (i, c) in s.iter().enumerate() {
if c.is_ascii_alphanumeric()
|| *c == b'-'
@ -226,6 +221,15 @@ mod tests {
assert_eq!(example_nix_path_str, nixpath.to_string())
}
/// This is the store path produced after `nix-store --add`'ing an
/// empty `.gitignore` file.
#[test]
fn starts_with_dot() {
let nix_path_str = "fli4bwscgna7lpm7v5xgnjxrxh0yc7ra-.gitignore";
let nixpath = StorePath::from_bytes(nix_path_str.as_bytes()).expect("must succeed");
assert_eq!(".gitignore", nixpath.name);
}
#[test]
fn invalid_hash_length() {
StorePath::from_bytes(b"00bgd045z0d4icpbc2yy-net-tools-1.60_p20170221182432")