From 436b0da13812d4ec9ba4cc6c969ff153e5b78a7e Mon Sep 17 00:00:00 2001 From: Nathan Broadbent Date: Tue, 23 Oct 2012 23:34:15 +1300 Subject: [PATCH] Further ll fixes for escaped spaces and quotes! --- lib/git/shell_shortcuts.sh | 4 +--- lib/git/status_shortcuts.sh | 2 +- test/lib/git/shell_shortcuts_test.sh | 18 ++++++++++++------ 3 files changed, 14 insertions(+), 10 deletions(-) diff --git a/lib/git/shell_shortcuts.sh b/lib/git/shell_shortcuts.sh index 1134fdd..532eb61 100644 --- a/lib/git/shell_shortcuts.sh +++ b/lib/git/shell_shortcuts.sh @@ -154,13 +154,11 @@ EOF else ll_files="$(\ls "$@")" fi - # Escape single and double quotes - ll_files=$(echo "$ll_files" | \sed -e 's/"/\\\\\\"/g' -e "s/'"'/\\\\'"'/g") OLDIFS="$IFS"; IFS=$'\n' for file in $ll_files; do if [ -n "$rel_path" ]; then file="$rel_path/$file"; fi - export $git_env_char$e="$(eval $_abs_path_command \"$file\")" + export $git_env_char$e="$(eval $_abs_path_command \"${file//\"/\\\"}\")" if [ "${scmbDebug:-}" = "true" ]; then echo "Set \$$git_env_char$e => $file"; fi let e++ done diff --git a/lib/git/status_shortcuts.sh b/lib/git/status_shortcuts.sh index 345dcb4..2b6bde6 100644 --- a/lib/git/status_shortcuts.sh +++ b/lib/git/status_shortcuts.sh @@ -138,7 +138,7 @@ scmb_expand_args() { # Execute a command with expanded args, e.g. Delete files 6 to 12: $ ge rm 6-12 # Fails if command is a number or range (probably not worth fixing) -exec_scmb_expand_args() { eval "$(scmb_expand_args "$@" | sed -e 's/\([][()<>^ ]\)/\\\1/g')"; } +exec_scmb_expand_args() { eval "$(scmb_expand_args "$@" | sed -e "s/\([][()<>^ \"']\)/"'\\\1/g')"; } # Clear numbered env variables git_clear_vars() { diff --git a/test/lib/git/shell_shortcuts_test.sh b/test/lib/git/shell_shortcuts_test.sh index 8608439..e5c860e 100755 --- a/test/lib/git/shell_shortcuts_test.sh +++ b/test/lib/git/shell_shortcuts_test.sh @@ -86,14 +86,20 @@ test_ls_with_file_shortcuts() { assertIncludes "$ls_output" '[5] test_file' F # Test filenames with single or double quotes escaped - assertEquals "$TEST_DIR/a \\\"b\\\"" "$e1" - assertEquals "$TEST_DIR/a \\'b\\'" "$e2" - assertEquals "$TEST_DIR/a [b]" "$e3" - assertEquals "$TEST_DIR/test file" "$e4" - assertEquals "$TEST_DIR/test_file" "$e5" + assertEquals "$TEST_DIR/"'a "b"' "$e1" + assertEquals "$TEST_DIR/a 'b'" "$e2" + assertEquals "$TEST_DIR/a [b]" "$e3" + assertEquals "$TEST_DIR/test file" "$e4" + assertEquals "$TEST_DIR/test_file" "$e5" # Test ls with subdirectory - ls_output=$(ls_with_file_shortcuts "a \"b\"" | strip_colors) + ls_with_file_shortcuts 'a "b"' > $temp_file + ls_output=$(<$temp_file strip_colors) + assertIncludes "$ls_output" '[1] c' F + # Test that env variable is set correctly + assertEquals "$TEST_DIR/a \"b\"/c" "$e1" + # Test arg with no quotes + ls_output=$(ls_with_file_shortcuts a\ \"b\" | strip_colors) assertIncludes "$ls_output" '[1] c' F }