Closed future-pirate-king closed 3 years ago
@future-pirate-king where did you get that diff from?
I am asking because it is not a valid unified diff, since the lines with ---
and +++
are missing in the first file.
so this is generated using these commands
update: for diff example create a new folder with space in folder name and add a new empty file then execute the above commands to get the diff
That is indeed a very interesting corner case.
I think it is impossible to solve in a simple way.
Since it is not a valid unified diff, due to the lines with ---
and +++
and since the only header available does not have a clear separator between the file paths, it is very error prone to know the names using it.
Do you have any suggestions?
currently this line of code is parsing the filenames for this case https://github.com/rtfpessoa/diff2html/blob/73ab5ba05059dd476fbbb0b4b1f50a005aae38b7/src/diff-parser.ts#L279
if we change the regex to
^diff --git "?(a\/.+)"? "?(b\/.+)"?
seems to work. @rtfpessoa what do you think ?
That is a not going to work if the first path has a b/
in it. But probably it is not worse than it is right now.
yes @rtfpessoa , that was just an example. if we know the possible prefixes we can create regex like this
^diff --git "?([abiwco]\/.+)"? "?([abiwco]\/.+)"?
or
^diff --git "?([a-z]\/.+)"? "?([a-z]\/.+)"?
it will work for a/
, b/
or any of the alphabets inside square brackets.
The problem is not the types of prefixes if if the paths have spaces and a path like this will parse incorrectly still:
diff --git a/my/amazing b/path.js b/new/different/path.js
Anyway since it does not stay worse than what it is now I went ahead and merged the update. Let me know how it goes.
Released as version 3.4.7
Hello @rtfpessoa
I feel this issue is still there. I use the parse
method and it appends \t
at the end and destroys the value. Can you please check this?
P.S: using 3.4.22
version
Can you provide an example?
Step -1: Before filling an issue check out troubleshooting section
Step 0: Describe your environment
Step 1: Describe the problem:
when user creates a folder or file with name some which has space in it then the parsed output of unified diff is giving wrong fileName
Steps to reproduce:
diff example:
Observed Results:
Expected Results:
newName: "notebooks/Untitled Folder/untitled.txt" oldName: "notebooks/Untitled Folder/untitled.txt"
Relevant Code: