Skip to content

Commit

Permalink
filter-repo: add tests for --replace-text in binary blobs
Browse files Browse the repository at this point in the history
The --replace-text failed to detect blobs as binary and incorrectly
applied to all blobs.
Prior to switch from python2 to python3 it incorrectly designated blobs
containing 0 character instead of NUL byte as binary and would have been
causing text replacements to apply to binary files and not apply to text
files containing 0 character.

Add regression tests with blobs containing; 0 character, NUL byte, and
both 0 character and NUL byte.

Signed-off-by: rndbit <[email protected]>
  • Loading branch information
rndbit committed Sep 2, 2021
1 parent 9cfe2b4 commit 9932167
Showing 1 changed file with 81 additions and 0 deletions.
81 changes: 81 additions & 0 deletions t/t9390-filter-repo.sh
Original file line number Diff line number Diff line change
Expand Up @@ -850,6 +850,87 @@ test_expect_success '--replace-text all options' '
)
'

test_expect_success '--replace-text binary zero_byte-0_char' '
(
set -e
set -u
REPO=replace-text-detect-binary
FILE=mangle.bin
OLD_STR=replace-from
NEW_STR=replace-with
# used with printf, contains a zero byte and a "0" character, binary
OLD_CONTENT_FORMAT="${OLD_STR}\\0${OLD_STR}\\n0\\n"
# expect content unchanged due to binary
NEW_CONTENT_FORMAT="${OLD_CONTENT_FORMAT}"
rm -rf "${REPO}"
git init "${REPO}"
cd "${REPO}"
echo "${OLD_STR}==>${NEW_STR}" >../replace-rules
printf "${NEW_CONTENT_FORMAT}" > ../expect
printf "${OLD_CONTENT_FORMAT}" > "${FILE}"
git add "${FILE}"
git commit -m 'test'
git filter-repo --force --replace-text ../replace-rules
test_cmp ../expect "${FILE}"
)
'

test_expect_success '--replace-text binary zero_byte-no_0_char' '
(
set -e
set -u
REPO=replace-text-detect-binary
FILE=mangle.bin
OLD_STR=replace-from
NEW_STR=replace-with
# used with printf, contains a zero byte but no "0" character, binary
OLD_CONTENT_FORMAT="${OLD_STR}\\0${OLD_STR}\\n"
# expect content unchanged due to binary
NEW_CONTENT_FORMAT="${OLD_CONTENT_FORMAT}"
rm -rf "${REPO}"
git init "${REPO}"
cd "${REPO}"
echo "${OLD_STR}==>${NEW_STR}" >../replace-rules
printf "${NEW_CONTENT_FORMAT}" > ../expect
printf "${OLD_CONTENT_FORMAT}" > "${FILE}"
git add "${FILE}"
git commit -m 'test'
git filter-repo --force --replace-text ../replace-rules
test_cmp ../expect "${FILE}"
)
'

test_expect_success '--replace-text text-file no_zero_byte-zero_char' '
(
set -e
set -u
REPO=replace-text-detect-binary
FILE=mangle.bin
OLD_STR=replace-from
NEW_STR=replace-with
# used with printf, contains no zero byte but contains a "0" character, text
OLD_CONTENT_FORMAT="${OLD_STR}0\\n0${OLD_STR}\\n0\\n"
# expect content changed due to text
NEW_CONTENT_FORMAT="${NEW_STR}0\\n0${NEW_STR}\\n0\\n"
rm -rf "${REPO}"
git init "${REPO}"
cd "${REPO}"
echo "${OLD_STR}==>${NEW_STR}" >../replace-rules
printf "${NEW_CONTENT_FORMAT}" > ../expect
printf "${OLD_CONTENT_FORMAT}" > "${FILE}"
git add "${FILE}"
git commit -m 'test'
git filter-repo --force --replace-text ../replace-rules
test_cmp ../expect "${FILE}"
)
'

test_expect_success '--strip-blobs-bigger-than' '
setup_analyze_me &&
(
Expand Down

0 comments on commit 9932167

Please sign in to comment.