Skip to content

Commit f3c1b37

Browse files
committed
Address CodeRabbit review: resolve escape roundtrip
1 parent 30a2627 commit f3c1b37

2 files changed

Lines changed: 11 additions & 4 deletions

File tree

lib/core.sh

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -351,8 +351,8 @@ EOF
351351
_tsv_escape_field() {
352352
local value="$1"
353353
value=${value//\\/\\\\}
354-
value=${value//$'\t'/\\\\t}
355-
value=${value//$'\n'/\\\\n}
354+
value=${value//$'\t'/$'\\t'}
355+
value=${value//$'\n'/$'\\n'}
356356
printf "%s" "$value"
357357
}
358358

@@ -488,8 +488,7 @@ EOF
488488
unpack_target() {
489489
local escaped_path escaped_branch
490490
local IFS=$'\t'
491-
# shellcheck disable=SC2162
492-
read _ctx_is_main escaped_path escaped_branch <<< "$1"
491+
read -r _ctx_is_main escaped_path escaped_branch <<< "$1"
493492
_ctx_worktree_path=$(_tsv_unescape_field "$escaped_path")
494493
_ctx_branch=$(_tsv_unescape_field "$escaped_branch")
495494
}

tests/core_resolve_target.bats

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,14 @@ teardown() {
6868
[ "$_ctx_branch" = "main" ]
6969
}
7070

71+
@test "resolved target escaping round-trips tabs newlines and backslashes" {
72+
local value="/tmp/path"$'\t'"with"$'\n'"chars\\tail"
73+
local escaped
74+
escaped=$(_tsv_escape_field "$value")
75+
76+
[ "$(_tsv_unescape_field "$escaped")" = "$value" ]
77+
}
78+
7179
@test "resolve_worktree sets context globals" {
7280
create_test_worktree "ctx-test"
7381
resolve_worktree "ctx-test" "$TEST_REPO" "$TEST_WORKTREES_DIR" ""

0 commit comments

Comments
 (0)