Skip to content

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

Closed
@ExplodingCabbage

Description

@ExplodingCabbage

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.

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions