File tree 5 files changed +34
-6
lines changed
5 files changed +34
-6
lines changed Original file line number Diff line number Diff line change @@ -34,3 +34,4 @@ Contributors
34
34
* (`@cpackham-atlnz`)
35
35
* David Leen (`@dleen`)
36
36
* Martin Liška (`@marxin`)
37
+ * Tushar Sadhwani (`@tushar-deepsource`)
Original file line number Diff line number Diff line change
1
+ diff --git "a/A \303\242 B.py" "b/A \303\242 B.py"
2
+ new file mode 100644
3
+ index 0000000..ce01362
4
+ --- /dev/null
5
+ +++ "b/A \303\242 B.py"
6
+ @@ -0,0 +1 @@
7
+ + hello
Original file line number Diff line number Diff line change 1
1
# -*- coding: utf-8 -*-
2
2
3
3
# The MIT License (MIT)
4
- # Copyright (c) 2014-2021 Matias Bordese
4
+ # Copyright (c) 2014-2023 Matias Bordese
5
5
#
6
6
# Permission is hereby granted, free of charge, to any person obtaining a copy
7
7
# of this software and associated documentation files (the "Software"), to deal
@@ -337,6 +337,19 @@ def test_parse_filename_prefix_with_spaces(self):
337
337
self .assertTrue (res [0 ].is_added_file )
338
338
self .assertEqual (res [0 ].path , 'dst://foo bar/baz' )
339
339
340
+ def test_parse_quoted_filename (self ):
341
+ filename = os .path .join (self .samples_dir , 'samples/git_quoted_filename.diff' )
342
+ with open (filename ) as f :
343
+ res = PatchSet (f )
344
+
345
+ self .assertEqual (len (res ), 1 )
346
+
347
+ self .assertEqual (res [0 ].source_file , '/dev/null' )
348
+ self .assertEqual (res [0 ].target_file , '"b/A \\ 303\\ 242 B.py"' )
349
+ self .assertTrue (res [0 ].is_added_file )
350
+ self .assertEqual (res [0 ].path , '"A \\ 303\\ 242 B.py"' )
351
+
352
+
340
353
def test_deleted_file (self ):
341
354
filename = os .path .join (self .samples_dir , 'samples/git_delete.diff' )
342
355
with open (filename ) as f :
Original file line number Diff line number Diff line change 1
1
# -*- coding: utf-8 -*-
2
2
3
3
# The MIT License (MIT)
4
- # Copyright (c) 2014-2022 Matias Bordese
4
+ # Copyright (c) 2014-2023 Matias Bordese
5
5
#
6
6
# Permission is hereby granted, free of charge, to any person obtaining a copy
7
7
# of this software and associated documentation files (the "Software"), to deal
30
30
31
31
32
32
RE_SOURCE_FILENAME = re .compile (
33
- r'^--- (?P<filename>[^\t\n]+)(?:\t(?P<timestamp>[^\n]+))?' )
33
+ r'^--- (?P<filename>"? [^\t\n]+"? )(?:\t(?P<timestamp>[^\n]+))?' )
34
34
RE_TARGET_FILENAME = re .compile (
35
- r'^\+\+\+ (?P<filename>[^\t\n]+)(?:\t(?P<timestamp>[^\n]+))?' )
35
+ r'^\+\+\+ (?P<filename>"? [^\t\n]+"? )(?:\t(?P<timestamp>[^\n]+))?' )
36
36
37
37
38
38
# check diff git line for git renamed files support
39
39
RE_DIFF_GIT_HEADER = re .compile (
40
- r'^diff --git (?P<source>a/[^\t\n]+) (?P<target>b/[^\t\n]+)' )
40
+ r'^diff --git (?P<source>"? a/[^\t\n]+"? ) (?P<target>"? b/[^\t\n]+"? )' )
41
41
RE_DIFF_GIT_HEADER_URI_LIKE = re .compile (
42
42
r'^diff --git (?P<source>.*://[^\t\n]+) (?P<target>.*://[^\t\n]+)' )
43
43
RE_DIFF_GIT_HEADER_NO_PREFIX = re .compile (
Original file line number Diff line number Diff line change 1
1
# -*- coding: utf-8 -*-
2
2
3
3
# The MIT License (MIT)
4
- # Copyright (c) 2014-2022 Matias Bordese
4
+ # Copyright (c) 2014-2023 Matias Bordese
5
5
#
6
6
# Permission is hereby granted, free of charge, to any person obtaining a copy
7
7
# of this software and associated documentation files (the "Software"), to deal
@@ -393,9 +393,16 @@ def path(self):
393
393
# if this is a rename, prefer the target filename
394
394
filepath = self .target_file
395
395
396
+ quoted = filepath .startswith ('"' ) and filepath .endswith ('"' )
397
+ if quoted :
398
+ filepath = filepath [1 :- 1 ]
399
+
396
400
if filepath .startswith ('a/' ) or filepath .startswith ('b/' ):
397
401
filepath = filepath [2 :]
398
402
403
+ if quoted :
404
+ filepath = '"{}"' .format (filepath )
405
+
399
406
return filepath
400
407
401
408
@property
You can’t perform that action at this time.
0 commit comments