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

applyPatch with a fuzzFactor will happily delete an entirely different line to the one shown in the diff #468

Open
ExplodingCabbage opened this issue Jan 8, 2024 · 1 comment

Comments

@ExplodingCabbage
Copy link
Collaborator

ExplodingCabbage commented Jan 8, 2024

Surely these behaviours can't be intended?

> text1 = 'foo\nbar\nbaz\nqux\n'
'foo\nbar\nbaz\nqux\n'
> text2 = 'foo\nbaz\nqux\n'
'foo\nbaz\nqux\n'
> patch = diff.createPatch('foo.txt', text1, text2)
'Index: foo.txt\n' +
  '===================================================================\n' +
  '--- foo.txt\n' +
  '+++ foo.txt\n' +
  '@@ -1,4 +1,3 @@\n' +
  ' foo\n' +
  '-bar\n' +
  ' baz\n' +
  ' qux\n'
> diff.applyPatch('foo\nSOMETHING ENTIRELY DIFFERENT\nbaz\nqux\n', patch, {fuzzFactor: 1})
'foo\nbaz\nqux\n'
> diff.applyPatch(text2, patch, {fuzzFactor: 3})
'foo\nqux\n'

Git and GNU patch would both never do this (even with patch --fuzz 99999999999999). It seems straightforwardly wrong to me that a patch line that says -bar could ever delete a line whose content is anything other than bar.

@ExplodingCabbage
Copy link
Collaborator Author

As part of fixing this issue, we should document exactly how fuzzFactor works in the README.

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

No branches or pull requests

1 participant