Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue parsing files with space in filename #93

Closed
dperecab opened this issue Feb 21, 2022 · 5 comments · Fixed by #95
Closed

Issue parsing files with space in filename #93

dperecab opened this issue Feb 21, 2022 · 5 comments · Fixed by #95

Comments

@dperecab
Copy link

Whenever there is a space in the route of the file, I keep getting the following error:

File "/usr/local/lib/python3.9/site-packages/unidiff/patch.py", line 460, in __init__ self._parse(data, encoding=encoding, metadata_only=metadata_only) File "/usr/local/lib/python3.9/site-packages/unidiff/patch.py", line 530, in _parse raise UnidiffParseError('Target without source: %s' % line) unidiff.errors.UnidiffParseError: Target without source: +++ b/Audit Repositories/Interfaces/IMaintTransactionRepository.cs

This is an example:
diff --git a/Audit Repositories/Interfaces/IMaintTransactionRepository.cs b/Audit Repositories/Interfaces/IMaintTransactionRepository.cs new file mode 100644 index 0000000..f95add3

or another one:
diff --git a/repairer_allocation_etl/src/test/resources/NCR API GW.postman_collection.json b/repairer_allocation_etl/src/test/resources/NCR API GW.postman_collection.json new file mode 100644 index 0000000..fdd8387

While debugging, I've seen that current_file.target_file is set to "Repositories/Interfaces/IMaintTransactionRepository.cs", while target_file is being correctly set to "b/Audit Repositories/Interfaces/IMaintTransactionRepository.cs"

@krobelus
Copy link

krobelus commented Feb 21, 2022 via email

@matiasb
Copy link
Owner

matiasb commented Mar 27, 2022

To confirm, was this related to a trailing tab character as mentioned? That would probably break the parsing regex, but I guess there shouldn't be a tab there? If you are still having issues, let me know, and if possible share some specific example and/or how you generate the diff. Thanks!

@dperecab
Copy link
Author

dperecab commented Apr 1, 2022

It is the space character in the path of the file what is causing the issue.
There is an if in row 529 of patch.py with this condition: current_file.target_file == target_file
When there is a space character in the path of the file, this validation does not match, causing the error

@DevArcana
Copy link

Changing the regex to the following seems to fix this type of error:

RE_DIFF_GIT_HEADER = re.compile(
    r'^diff --git (?P<source>a/.+) (?P<target>b/.+)')

Can anyone shed some light on whether that is going to break anything?

@asottile-sentry
Copy link
Contributor

here's a minimal patch which triggers this issue:

diff --git a/has spaces/t.sql b/has spaces/t.sql
new file mode 100644
index 0000000..8a9b485
--- /dev/null
+++ b/has spaces/t.sql
@@ -0,0 +1 @@
+select * FROM t;

0.7.2 seems to be the first version with this issue

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants