Skip to content

Commit

Permalink
zarrs_storage: Fix data_key on windows (#85)
Browse files Browse the repository at this point in the history
Also validate that chunk keys do not contain '//'.
  • Loading branch information
LDeakin authored Oct 7, 2024
1 parent b44282e commit 46bd880
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 8 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- **Breaking**: Change `output` parameter of `decode_into` codec trait methods to `&UnsafeCellSlice<u8>`
- **Breaking**: Add `dynamic()` to all `CodecTraits`
- **Breaking**: Add `options` parameter to `[Async]ArrayPartialDecoderTraits::partial_decode` and remove `partial_decode_opt`
- Bump `zarrs_storage` to 0.2.2

## [0.17.0] - 2024-10-02

Expand Down
11 changes: 6 additions & 5 deletions zarrs/src/node/key.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
use std::path::PathBuf;

use crate::storage::StoreKey;

use super::NodePath;
Expand Down Expand Up @@ -54,7 +52,10 @@ pub fn meta_key_v2_attributes(path: &NodePath) -> StoreKey {
pub fn data_key(path: &NodePath, chunk_key: &StoreKey) -> StoreKey {
let path = path.as_str();
let path = path.strip_prefix('/').unwrap_or(path);
let mut key_path = PathBuf::from(path);
key_path.push(chunk_key.as_str());
unsafe { StoreKey::new_unchecked(key_path.to_string_lossy().to_string()) }
let key_path = if path.is_empty() {
chunk_key.as_str().to_string()
} else {
format!("{}/{}", path, chunk_key.as_str())
};
unsafe { StoreKey::new_unchecked(key_path) }
}
2 changes: 2 additions & 0 deletions zarrs_storage/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Changed
- Bump `unsafe_cell_slice` to 0.2.0
- Validate that chunk keys do not contain '//'

### Fixed
- Fix new clippy warnings
- Fix `data_key` encoding on windows (it contained '//')

## [0.2.1] - 2024-09-22

Expand Down
8 changes: 5 additions & 3 deletions zarrs_storage/src/store_key.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,11 +53,13 @@ impl StoreKey {
/// Validates a key according to the following rule from the specification:
/// - a key is a Unicode string, where the final character is not a `/` character.
///
/// Additionally, a key which starts with '/' is invalid even though this is not explicit in the specification.
/// A key cannot be an empty string.
/// Additional checks (not in the specification):
/// - a key which starts with '/' is invalid, and
/// - a key that contains '//' is invalid, and
/// - a key cannot be an empty string.
#[must_use]
pub fn validate(key: &str) -> bool {
!key.starts_with('/') && !key.ends_with('/') && !key.is_empty()
!key.starts_with('/') && !key.ends_with('/') && !key.is_empty() && !key.contains("//")
}

/// Returns true if the key has prefix `prefix`.
Expand Down

0 comments on commit 46bd880

Please sign in to comment.