From 1c7b384e933ce80a44660f85862aaad960168f70 Mon Sep 17 00:00:00 2001 From: Xiangyu Zhu Date: Mon, 27 Jul 2026 15:43:35 +0800 Subject: [PATCH 1/2] fix(pwd): guard truncation-branch string ops with -- for leading-dash dirs --- functions/_tide_pwd.fish | 8 ++++---- tests/_tide_item_pwd.test.fish | 8 ++++++++ 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/functions/_tide_pwd.fish b/functions/_tide_pwd.fish index 5447dd44..a5bc9877 100644 --- a/functions/_tide_pwd.fish +++ b/functions/_tide_pwd.fish @@ -25,16 +25,16 @@ eval "function _tide_pwd if path is \$parent_dir/\$dir_section/\$tide_pwd_markers set split_output[\$i] \"$color_anchors\$dir_section$reset_to_color_dirs\" else if test \$_tide_pwd_len -gt \$dist_btwn_sides - string match -qr \"(?\..|.)\" \$dir_section + string match -qr \"(?\..|.)\" -- \$dir_section set -l glob \$parent_dir/\$trunc*/ set -e glob[(contains -i \$parent_dir/\$dir_section/ \$glob)] # This is faster than inverse string match - while string match -qr \"^\$parent_dir/\$(string escape --style=regex \$trunc)\" \$glob && - string match -qr \"(?\$(string escape --style=regex \$trunc).)\" \$dir_section + while string match -qr \"^\$parent_dir/\$(string escape --style=regex -- \$trunc)\" \$glob && + string match -qr \"(?\$(string escape --style=regex -- \$trunc).)\" -- \$dir_section end test -n \"\$trunc\" && set split_output[\$i] \"$color_truncated\$trunc$reset_to_color_dirs\" && - string join / \$split_output | string length -V | read _tide_pwd_len + string join / -- \$split_output | string length -V | read _tide_pwd_len end end diff --git a/tests/_tide_item_pwd.test.fish b/tests/_tide_item_pwd.test.fish index 826d691c..ea7f8186 100644 --- a/tests/_tide_item_pwd.test.fish +++ b/tests/_tide_item_pwd.test.fish @@ -130,5 +130,13 @@ mkdir -p "$tmpdir/tmp/[hello" _pwd $tmpdir/tmp/$longDirWithDot # CHECK: ~/t/[t/b/c/d/e/f/golf/hotel/india/juliett/kilo/lima/mike/november/oscar/papa command rm -r "$tmpdir/tmp/[hello" +# ---------- Truncation with a leading-dash directory ---------- +set -l longDirDash -alfa/bravo/charlie/delta/echo/foxtrot/golf/hotel/india/juliett/kilo/lima/mike/november/oscar/papa +_pwd $tmpdir/tmp/$longDirDash # CHECK: ~/t/-/b/c/d/e/f/golf/hotel/india/juliett/kilo/lima/mike/november/oscar/papa + +mkdir -p $tmpdir/tmp/-alfawolf +_pwd $tmpdir/tmp/$longDirDash # CHECK: ~/t/-alfa/b/c/d/e/f/golf/hotel/india/juliett/kilo/lima/mike/november/oscar/papa +command rm -r $tmpdir/tmp/-alfawolf + # ------------------------------------Cleanup------------------------------------ command rm -r $tmpdir From 524be080c6262ee0fb454919fdcc1b890343ca9b Mon Sep 17 00:00:00 2001 From: Xiangyu Zhu Date: Sat, 8 Aug 2026 18:17:16 +0800 Subject: [PATCH 2/2] test(pwd): isolate leading-dash truncation case --- tests/_tide_item_pwd.test.fish | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/_tide_item_pwd.test.fish b/tests/_tide_item_pwd.test.fish index ea7f8186..450dd19d 100644 --- a/tests/_tide_item_pwd.test.fish +++ b/tests/_tide_item_pwd.test.fish @@ -110,6 +110,7 @@ _pwd "$tmpdir/tmp/has spaces/foo" # CHECK: ~/tmp/has spaces/foo mkdir -p "$tmpdir/tmp/--has dashes/foo" _pwd "$tmpdir/tmp/--has dashes/foo" # CHECK: ~/tmp/--has dashes/foo +command rm -r "$tmpdir/tmp/--has dashes" mkdir -p "$tmpdir/tmp/has'quotes''/foo" _pwd "$tmpdir/tmp/has'quotes''/foo" # CHECK: ~/tmp/has'quotes''/foo