Skip to content

Commit d22c40b

Browse files
authored
Merge pull request #467 from gitpython-developers/fix-dont-choke-on-invalid-unicode-paths
Don't choke on (legitimately) invalidly encoded Unicode paths
2 parents 4510b3c + 200d3c6 commit d22c40b

File tree

3 files changed

+18
-10
lines changed

3 files changed

+18
-10
lines changed

Diff for: git/diff.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -404,15 +404,15 @@ def _index_from_patch_format(cls, repo, stream):
404404
a_mode = old_mode or deleted_file_mode or (a_path and (b_mode or new_mode or new_file_mode))
405405
b_mode = b_mode or new_mode or new_file_mode or (b_path and a_mode)
406406
index.append(Diff(repo,
407-
a_path and a_path.decode(defenc),
408-
b_path and b_path.decode(defenc),
407+
a_path and a_path.decode(defenc, 'replace'),
408+
b_path and b_path.decode(defenc, 'replace'),
409409
a_blob_id and a_blob_id.decode(defenc),
410410
b_blob_id and b_blob_id.decode(defenc),
411411
a_mode and a_mode.decode(defenc),
412412
b_mode and b_mode.decode(defenc),
413413
new_file, deleted_file,
414-
rename_from and rename_from.decode(defenc),
415-
rename_to and rename_to.decode(defenc),
414+
rename_from and rename_from.decode(defenc, 'replace'),
415+
rename_to and rename_to.decode(defenc, 'replace'),
416416
None))
417417

418418
previous_header = header

Diff for: git/test/fixtures/diff_patch_unsafe_paths

+7
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,13 @@ index 0000000000000000000000000000000000000000..eaf5f7510320b6a327fb308379de2f94
6868
+++ "b/path/\360\237\222\251.txt"
6969
@@ -0,0 +1 @@
7070
+dummy content
71+
diff --git "a/path/\200-invalid-unicode-path.txt" "b/path/\200-invalid-unicode-path.txt"
72+
new file mode 100644
73+
index 0000000000000000000000000000000000000000..eaf5f7510320b6a327fb308379de2f94d8859a54
74+
--- /dev/null
75+
+++ "b/path/\200-invalid-unicode-path.txt"
76+
@@ -0,0 +1 @@
77+
+dummy content
7178
diff --git a/a/with spaces b/b/with some spaces
7279
similarity index 100%
7380
rename from a/with spaces

Diff for: git/test/test_diff.py

+7-6
Original file line numberDiff line numberDiff line change
@@ -162,16 +162,17 @@ def test_diff_unsafe_paths(self):
162162
self.assertEqual(res[7].b_path, u'path/with-question-mark?')
163163
self.assertEqual(res[8].b_path, u'path/¯\\_(ツ)_|¯')
164164
self.assertEqual(res[9].b_path, u'path/💩.txt')
165+
self.assertEqual(res[10].b_path, u'path/�-invalid-unicode-path.txt')
165166

166167
# The "Moves"
167168
# NOTE: The path prefixes a/ and b/ here are legit! We're actually
168169
# verifying that it's not "a/a/" that shows up, see the fixture data.
169-
self.assertEqual(res[10].a_path, u'a/with spaces') # NOTE: path a/ here legit!
170-
self.assertEqual(res[10].b_path, u'b/with some spaces') # NOTE: path b/ here legit!
171-
self.assertEqual(res[11].a_path, u'a/ending in a space ')
172-
self.assertEqual(res[11].b_path, u'b/ending with space ')
173-
self.assertEqual(res[12].a_path, u'a/"with-quotes"')
174-
self.assertEqual(res[12].b_path, u'b/"with even more quotes"')
170+
self.assertEqual(res[11].a_path, u'a/with spaces') # NOTE: path a/ here legit!
171+
self.assertEqual(res[11].b_path, u'b/with some spaces') # NOTE: path b/ here legit!
172+
self.assertEqual(res[12].a_path, u'a/ending in a space ')
173+
self.assertEqual(res[12].b_path, u'b/ending with space ')
174+
self.assertEqual(res[13].a_path, u'a/"with-quotes"')
175+
self.assertEqual(res[13].b_path, u'b/"with even more quotes"')
175176

176177
def test_diff_patch_format(self):
177178
# test all of the 'old' format diffs for completness - it should at least

0 commit comments

Comments
 (0)