Skip to content

Commit 5019813

Browse files
committed
Fix listing of file names with special characters to avoid crash and unrecognised names #204
Tweak the file listing to fix two issues found to affect files with problematic names like `"Terrible file""")))(((][][].secret`. This change may undo performance improvements achieved in #193. - Ensure the `git check-attr filter` command does not quote file name characters by using `-z` arg and some extra trickery to keep space and newline delimiter characters for filter metadata and each file name respectively. This fixes a file named `"Terrible file""")))(((][][].secret` being listed as just `Terrible file`. - Adjust checking for `filter` and `crypt` strings to work with changed output from `check-attr` command. - Tweak `eval 'echo $filename'` portion of command to avoid script crash on files with special characters with error message like `eval: line 192: syntax error near unexpected token`
1 parent efd42e5 commit 5019813

File tree

1 file changed

+13
-5
lines changed

1 file changed

+13
-5
lines changed

transcrypt

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -178,18 +178,26 @@ _list_encrypted_files() {
178178
# regardless of core.quotePath=false as per
179179
# https://git-scm.com/docs/git-config#Documentation/git-config.txt-corequotePath
180180
git -c core.quotePath=false ls-files -z | tr '\0' '\n' |
181-
git -c core.quotePath=false check-attr filter --stdin 2>/dev/null |
181+
# Read unquoted filenames one at a time per newline delimiters and use
182+
# check-attr to print filter info, with some trickery to keep filename
183+
# unquoted (-z) with space-delimited filter status and anewline
184+
# delimiting of each file name
185+
while read -r filename
186+
do
187+
git -c core.quotePath=false check-attr filter -z 2>/dev/null -- "$filename" | tr '\0' ' '
188+
echo
189+
done |
182190
{
183191
# Only output names of encrypted files matching the context, either
184192
# strictly (if $1 = "true") or loosely (if $1 is false or unset)
185193
if [[ "$strict_context" == "true" ]]; then
186-
grep ": filter: crypt${CONTEXT_CRYPT_SUFFIX:-}$" || true
194+
grep " filter crypt${CONTEXT_CRYPT_SUFFIX:-}$" || true
187195
else
188-
grep ": filter: crypt${CONTEXT_CRYPT_SUFFIX:-}.*$" || true
196+
grep " filter crypt${CONTEXT_CRYPT_SUFFIX:-}.*$" || true
189197
fi
190198
} |
191-
sed "s|: filter: crypt${CONTEXT_CRYPT_SUFFIX:-}.*||" |
192-
while read -r file; do eval "echo $file"; done
199+
sed "s| filter crypt${CONTEXT_CRYPT_SUFFIX:-}.*||" |
200+
while read -r filename; do eval 'echo $filename'; done
193201
}
194202

195203
# Detect OpenSSL major version 3 or later which requires a compatibility

0 commit comments

Comments
 (0)