From 155f53b264436c012efc272b45f6fb4532c09338 Mon Sep 17 00:00:00 2001 From: edef Date: Wed, 4 Oct 2023 17:04:12 +0000 Subject: fix(tvix/nix-compat): reject dotfiles Nix has historically rejected these. The current behaviour was accidentally introduced in Nix 2.4, and is considered a bug. Link: https://github.com/NixOS/nix/pull/9095 Change-Id: I38ffa911f0a413086479bd972de09671dbe85121 Reviewed-on: https://cl.tvl.fyi/c/depot/+/9507 Reviewed-by: flokli Tested-by: BuildkiteCI Autosubmit: edef --- tvix/nix-compat/src/store_path/mod.rs | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) (limited to 'tvix') diff --git a/tvix/nix-compat/src/store_path/mod.rs b/tvix/nix-compat/src/store_path/mod.rs index b68a4f3171..d3317b67f6 100644 --- a/tvix/nix-compat/src/store_path/mod.rs +++ b/tvix/nix-compat/src/store_path/mod.rs @@ -163,9 +163,9 @@ pub(crate) fn validate_name(s: &[u8]) -> Result { for (i, c) in s.iter().enumerate() { if c.is_ascii_alphanumeric() + || (*c == b'.' && i != 0) // can't start with a dot || *c == b'-' || *c == b'_' - || *c == b'.' || *c == b'+' || *c == b'?' || *c == b'=' @@ -221,13 +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 + /// This is the store path rejected when `nix-store --add`'ing an /// empty `.gitignore` file. + /// + /// Nix 2.4 accidentally dropped this behaviour, but this is considered a bug. + /// See https://github.com/NixOS/nix/pull/9095. #[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); + StorePath::from_bytes(b"fli4bwscgna7lpm7v5xgnjxrxh0yc7ra-.gitignore") + .expect_err("must fail"); } #[test] -- cgit 1.4.1