Skip to content

Commit 574d003

Browse files
committed
Check that paths only contain normal components
1 parent e703a41 commit 574d003

File tree

3 files changed

+29
-7
lines changed

3 files changed

+29
-7
lines changed

Diff for: Cargo.lock

+1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: gix-object/Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ gix-hashtable = { version = "^0.8.0", path = "../gix-hashtable" }
4949
gix-validate = { version = "^0.9.4", path = "../gix-validate" }
5050
gix-actor = { version = "^0.34.0", path = "../gix-actor" }
5151
gix-date = { version = "^0.9.4", path = "../gix-date" }
52+
gix-fs = { version = "^0.14.0", path = "../gix-fs" }
5253
gix-path = { version = "^0.10.15", path = "../gix-path" }
5354
gix-utils = { version = "^0.2.0", path = "../gix-utils" }
5455

Diff for: gix-object/src/tree/mod.rs

+27-7
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
use bstr::ByteSlice;
2+
use gix_fs::stack::ToNormalPathComponents;
23

34
use crate::{
45
bstr::{BStr, BString},
@@ -380,18 +381,29 @@ impl std::ops::Index<std::ops::RangeTo<usize>> for RepositoryPathPuf {
380381

381382
///
382383
pub mod repository_path_buf {
384+
use gix_fs::stack::to_normal_path_components;
385+
383386
/// The error used in [`RepositoryPathPuf`](super::RepositoryPathPuf).
384387
#[derive(Debug, thiserror::Error)]
385388
#[allow(missing_docs)]
386-
pub enum Error {}
389+
pub enum Error {
390+
#[error(transparent)]
391+
ContainsNonNormalComponents(#[from] to_normal_path_components::Error),
392+
#[error(transparent)]
393+
IllegalUtf8(#[from] gix_path::Utf8Error),
394+
}
387395
}
388396

389397
impl TryFrom<&str> for RepositoryPathPuf {
390398
type Error = repository_path_buf::Error;
391399

392400
fn try_from(value: &str) -> Result<Self, Self::Error> {
393-
// TODO
394-
// Check whether the documented constraints are met, return `Err` if not.
401+
let path = std::path::Path::new(value);
402+
403+
for component in path.to_normal_path_components() {
404+
component?;
405+
}
406+
395407
Ok(Self { inner: value.into() })
396408
}
397409
}
@@ -400,8 +412,12 @@ impl TryFrom<&BStr> for RepositoryPathPuf {
400412
type Error = repository_path_buf::Error;
401413

402414
fn try_from(value: &BStr) -> Result<Self, Self::Error> {
403-
// TODO
404-
// Check whether the documented constraints are met, return `Err` if not.
415+
let path: &std::path::Path = &gix_path::try_from_bstr(value)?;
416+
417+
for component in path.to_normal_path_components() {
418+
component?;
419+
}
420+
405421
Ok(Self { inner: value.into() })
406422
}
407423
}
@@ -410,8 +426,12 @@ impl TryFrom<BString> for RepositoryPathPuf {
410426
type Error = repository_path_buf::Error;
411427

412428
fn try_from(value: BString) -> Result<Self, Self::Error> {
413-
// TODO
414-
// Check whether the documented constraints are met, return `Err` if not.
429+
let path: &std::path::Path = &gix_path::try_from_bstr(&value)?;
430+
431+
for component in path.to_normal_path_components() {
432+
component?;
433+
}
434+
415435
Ok(Self { inner: value })
416436
}
417437
}

0 commit comments

Comments
 (0)