Skip to content

Commit 9cfe2b4

Browse files
author
rndbit
committed
filter-repo: fix detection of binary blobs for --replace-text
Detection if blob is binary for the purpose of --replace-text always fails and text replacement is applied to all blobs. This has changed going to python3. With python2 the same code would still be wrong but would manifest differently. In the construct 'for x in b"..."' the x is - of type <int> in python3 - of type <str> in python2 thus in python3 condition 'x == b"\0"' can not be true for any x due to type difference. Further, the search was supposed to look for NUL byte and not 0 character, thus change to b"\0" instead of b"0". Signed-off-by: rndbit <[email protected]>
1 parent d8e858a commit 9cfe2b4

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

git-filter-repo

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3261,8 +3261,10 @@ class RepoFilter(object):
32613261
if blob.original_id in self._args.strip_blobs_with_ids:
32623262
blob.skip()
32633263

3264-
if self._args.replace_text and \
3265-
not any(x == b"0" for x in blob.data[0:8192]):
3264+
if ( self._args.replace_text
3265+
# not (if blob contains zero byte in the first 8Kb, that is, if blob is binary data)
3266+
and not b"\0" in blob.data[0:8192]
3267+
):
32663268
for literal, replacement in self._args.replace_text['literals']:
32673269
blob.data = blob.data.replace(literal, replacement)
32683270
for regex, replacement in self._args.replace_text['regexes']:

0 commit comments

Comments
 (0)