You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Aug 5, 2024. It is now read-only.
Repository navigation
This repository was archived by the owner on Aug 5, 2024. It is now read-only.
patch_fromText and lines breaks issue in Python #157
I am looking to utilize this fantastic library for applying patches to a file, but I'm encountering issues with broken line breaks. I have attempted to use the patch_make function to compare the behavior, and it operates effectively when the diff is generated by dmp. Could someone please guide me in identifying the potential issues in my diff file?
The wrong result :
"express": "^4.18.2", "lodash": "^4.17.21",
The expected one :
"express": "^4.18.2",
"lodash": "^4.17.21",
This is my simple test code :
fromdiff_match_patchimportdiff_match_patchoriginal_json='''{ "type": "module", "dependencies": { "ejs": "^3.1.9", "express": "^4.18.2", "puppeteer": "^21.7.0" }}'''expected_json='''{ "type": "module", "dependencies": { "ejs": "^3.1.9", "express": "^4.18.2", "lodash": "^4.17.21", "puppeteer": "^21.7.0" }}'''# The unidiff string, which is an exact clone of what dmp generates for the same changesdiff_str='''@@ -82,16 +82,42 @@ .18.2",+ "lodash": "^4.17.21", "pup'''print("____________ BROKEN EXAMPLE")
dmp=diff_match_patch()
patches=dmp.patch_fromText(diff_str)
patch_text=dmp.patch_toText(patches)
new_text, _=dmp.patch_apply(patches, original_json)
print(patch_text)
print(new_text)
print("____________ WORKING EXAMPLE")
patches=dmp.patch_make(original_json, expected_json)
patch_text=dmp.patch_toText(patches)
new_text, _=dmp.patch_apply(patches, original_json)
print(patch_text)
print(new_text)
there one thing that stands out: in the broken example we have a patch file where the newline is percent-encoded as %0A. it's becoming part of the diff, but the patch tool already works on the line-level.
makes me wonder if there's something about the diff output that patch takes that makes an assumption about a single trailing newline vs. many. as in, maybe diff-match-patch should strip a single trailing newline from its output before percent-encoding it.
@dmsnell I just encountered this issue myself. This bug is troublesome. Do you plan to fix it and publish the fix in your improved fork? ( https://github.com/dmsnell/diff-match-patch )? That would be great. Can't believe Google abandoned this project... 😔
@Emasoft it's doubtful I'll fix this myself on any timeline someone else wants, but I'm willing to work with people who propose fixes and get it merged. I don't have the capacity do everything myself.
Activity
dmsnell commentedon Apr 9, 2024
@weeger did you confirm if this works as expected in the other languages? in JavaScript, Java, Objective C, or any others?
weeger commentedon Apr 13, 2024
Same problem, just tested in Javascript :
Result
dmsnell commentedon Apr 24, 2024
there one thing that stands out: in the broken example we have a patch file where the newline is percent-encoded as
%0A. it's becoming part of the diff, but the patch tool already works on the line-level.makes me wonder if there's something about the
diffoutput thatpatchtakes that makes an assumption about a single trailing newline vs. many. as in, maybediff-match-patchshould strip a single trailing newline from its output before percent-encoding it.Emasoft commentedon Apr 28, 2024
@dmsnell I just encountered this issue myself. This bug is troublesome. Do you plan to fix it and publish the fix in your improved fork? ( https://github.com/dmsnell/diff-match-patch )? That would be great. Can't believe Google abandoned this project... 😔
dmsnell commentedon Apr 29, 2024
@Emasoft it's doubtful I'll fix this myself on any timeline someone else wants, but I'm willing to work with people who propose fixes and get it merged. I don't have the capacity do everything myself.
17351269 commentedon May 28, 2024
Lang