Skip to content

Commit

Permalink
add bash string escaping to _add_ignored_file (#626)
Browse files Browse the repository at this point in the history
  • Loading branch information
friedenberg authored Nov 21, 2020
1 parent 44be48d commit 39ab72f
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
- Error if 'tell' is used on an email address with multiple keys (#552)
- Don't let 'reveal' clobber secret files (#579)
- Updated test key fixture that had expired (#607)
- Escape filenames with special characters before adding to .gitignore

This comment has been minimized.

Copy link
@joshrabinowitz

joshrabinowitz Mar 16, 2022

Collaborator

note that this change was not in 0.3.3, and the changelog now reflects this


### Misc

Expand Down
2 changes: 1 addition & 1 deletion src/_utils/_git_secret_tools.sh
Original file line number Diff line number Diff line change
Expand Up @@ -335,7 +335,7 @@ function _add_ignored_file {
local full_path
full_path=$(_append_root_path '.gitignore')

echo "$filename" >> "$full_path"
printf '%q' "$filename" >> "$full_path"
}


Expand Down
2 changes: 2 additions & 0 deletions tests/_test_base.bash
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ export TEST_ATTACKER_USER="[email protected]"
export TEST_DEFAULT_FILENAME="space file" # has spaces
export TEST_SECOND_FILENAME="space file two" # has spaces
export TEST_THIRD_FILENAME="space file three" # has spaces
export TEST_FOURTH_FILENAME="space file three [] * $" # has spaces and special chars


function test_user_password {
Expand Down Expand Up @@ -303,6 +304,7 @@ function unset_current_state {
rm -vrf "${TEST_GPG_HOMEDIR:?}/${TEST_DEFAULT_FILENAME}" 2>&1 | sed 's/^/# unset_current_state: rm /'
rm -vrf "${TEST_GPG_HOMEDIR:?}/${TEST_SECOND_FILENAME}" 2>&1 | sed 's/^/# unset_current_state: rm /'
rm -vrf "${TEST_GPG_HOMEDIR:?}/${TEST_THIRD_FILENAME}" 2>&1 | sed 's/^/# unset_current_state: rm /'
rm -vrf "${TEST_GPG_HOMEDIR:?}/${TEST_FOURTH_FILENAME}" 2>&1 | sed 's/^/# unset_current_state: rm /'

# return to the base dir:
cd "$SECRET_PROJECT_ROOT" || exit 1
Expand Down
24 changes: 24 additions & 0 deletions tests/test_add.bats
Original file line number Diff line number Diff line change
Expand Up @@ -246,3 +246,27 @@ function teardown {
# Cleaning up:
rm "$filename1" "$filename2" ".gitignore"
}

@test "run 'add' for file with special chars" {
# Preparations:
local filename="$TEST_FOURTH_FILENAME"
echo "content" > "$filename"
echo "$filename" > ".gitignore"

run git secret add "$filename"
[ "$status" -eq 0 ]

# Ensuring that path mappings was set correctly:
local path_mappings
path_mappings=$(_get_secrets_dir_paths_mapping)

local files_list=$(cat "$path_mappings")
[ "$files_list" = "$filename" ]

# Ensuring the file is correctly git-ignored
run git check-ignore "$filename"
[ "$status" -eq 0 ]

# Cleaning up:
rm "$filename" ".gitignore"
}

0 comments on commit 39ab72f

Please sign in to comment.