aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--crates/shirabe-php-shim/src/lib.rs13
-rw-r--r--crates/shirabe/tests/cli.rs2
2 files changed, 11 insertions, 4 deletions
diff --git a/crates/shirabe-php-shim/src/lib.rs b/crates/shirabe-php-shim/src/lib.rs
index 609d320..362e20f 100644
--- a/crates/shirabe-php-shim/src/lib.rs
+++ b/crates/shirabe-php-shim/src/lib.rs
@@ -1053,8 +1053,17 @@ pub fn json_encode<T: serde::Serialize + ?Sized>(_value: &T) -> Option<String> {
todo!()
}
-pub fn dirname(_path: &str) -> String {
- todo!()
+pub fn dirname(path: &str) -> String {
+ if path.is_empty() {
+ return String::new();
+ }
+ match std::path::Path::new(path).parent() {
+ // No parent: the root itself, or a path made up solely of slashes.
+ None => "/".to_string(),
+ // Path::parent yields an empty path where PHP's dirname returns ".".
+ Some(parent) if parent.as_os_str().is_empty() => ".".to_string(),
+ Some(parent) => parent.to_str().expect("input was valid UTF-8").to_string(),
+ }
}
pub fn stream_get_contents(_stream: PhpMixed) -> Option<String> {
diff --git a/crates/shirabe/tests/cli.rs b/crates/shirabe/tests/cli.rs
index 196e93b..9fd6470 100644
--- a/crates/shirabe/tests/cli.rs
+++ b/crates/shirabe/tests/cli.rs
@@ -129,7 +129,6 @@ run_no_panic_tests! {
run_audit => "audit",
#[ignore = "currently panics"]
run_browse => "browse",
- #[ignore = "currently panics"]
run_bump => "bump",
#[ignore = "currently panics"]
run_check_platform_reqs => "check-platform-reqs",
@@ -182,6 +181,5 @@ run_no_panic_tests! {
run_suggests => "suggests",
#[ignore = "currently panics"]
run_update => "update",
- #[ignore = "currently panics"]
run_validate => "validate",
}