Skip to content

Commit

Permalink
fix(nix-compat/store_path): permit store paths with dots again
Browse files Browse the repository at this point in the history
Nix 2.4 accidentally permitted this behaviour, but the revert came
too late to beat Hyrum's law. It is now considered permissible.

Link: NixOS/nix#9867
Change-Id: Ie97777af6765fe1c12c8aa593afe1c9b69125775
Reviewed-on: https://cl.tvl.fyi/c/depot/+/11553
Tested-by: BuildkiteCI
Reviewed-by: flokli <[email protected]>
  • Loading branch information
edef1c committed May 1, 2024
1 parent 962b55e commit 7215622
Showing 1 changed file with 8 additions and 10 deletions.
18 changes: 8 additions & 10 deletions nix-compat/src/store_path/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -303,8 +303,7 @@ impl Serialize for StorePathRef<'_> {
}
}

/// NAME_CHARS contains `true` for bytes that are valid in store path names,
/// not accounting for '.' being permitted only past the first character.
/// NAME_CHARS contains `true` for bytes that are valid in store path names.
static NAME_CHARS: [bool; 256] = {
let mut tbl = [false; 256];
let mut c = 0;
Expand Down Expand Up @@ -332,10 +331,6 @@ pub(crate) fn validate_name(s: &(impl AsRef<[u8]> + ?Sized)) -> Result<&str, Err
return Err(Error::InvalidLength);
}

if s[0] == b'.' {
return Err(Error::InvalidName(s.to_vec(), 0));
}

let mut valid = true;
for &c in s {
valid = valid && NAME_CHARS[c as usize];
Expand Down Expand Up @@ -446,15 +441,18 @@ mod tests {
}
}

/// This is the store path rejected when `nix-store --add`'ing an
/// This is the store path *accepted* 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.
/// Nix 2.4 accidentally permitted this behaviour, but the revert came
/// too late to beat Hyrum's law. It is now considered permissible.
///
/// https://github.com/NixOS/nix/pull/9095 (revert)
/// https://github.com/NixOS/nix/pull/9867 (revert-of-revert)
#[test]
fn starts_with_dot() {
StorePath::from_bytes(b"fli4bwscgna7lpm7v5xgnjxrxh0yc7ra-.gitignore")
.expect_err("must fail");
.expect("must succeed");
}

#[test]
Expand Down

0 comments on commit 7215622

Please sign in to comment.