Skip to content

Commit 3e71240

Browse files
authored
Make parent_directory() of bare filename return . (#3313)
1 parent 917a306 commit 3e71240

2 files changed

Lines changed: 21 additions & 2 deletions

File tree

src/function.rs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -496,10 +496,16 @@ fn os_family(_context: Context) -> FunctionResult {
496496
}
497497

498498
fn parent_directory(_context: Context, path: &str) -> FunctionResult {
499-
Utf8Path::new(path)
499+
let parent = Utf8Path::new(path)
500500
.parent()
501501
.map(Utf8Path::to_string)
502-
.ok_or_else(|| format!("Could not extract parent directory from `{path}`"))
502+
.ok_or_else(|| format!("Could not extract parent directory from `{path}`"))?;
503+
504+
if parent.is_empty() {
505+
Ok(".".into())
506+
} else {
507+
Ok(parent)
508+
}
503509
}
504510

505511
fn path_exists(context: Context, path: &str) -> FunctionResult {

tests/functions.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -325,6 +325,19 @@ fn broken_directory_function2() {
325325
.failure();
326326
}
327327

328+
#[test]
329+
fn parent_directory_of_bare_filename() {
330+
Test::new()
331+
.justfile(
332+
"
333+
foo:
334+
@echo {{parent_directory('foo')}}
335+
",
336+
)
337+
.stdout(".\n")
338+
.success();
339+
}
340+
328341
#[test]
329342
fn env_var_functions_windows() {
330343
if cfg!(not(windows)) {

0 commit comments

Comments
 (0)