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

diffWords doesn't consistently ignore whitespace, despite the README saying it should #436

Closed
ExplodingCabbage opened this issue Dec 20, 2023 · 1 comment · Fixed by #497

Comments

@ExplodingCabbage
Copy link
Collaborator

The docs:

Diff.diffWords(oldStr, newStr[, options]) - diffs two blocks of text, comparing word by word, ignoring whitespace.

Here are some examples of this working as described:

> diff.diffWords("foo bar", "foo          bar")
[ { value: 'foo          bar', count: 3 } ]
> diff.diffWords("foo, bar", "foo,          bar")
[ { value: 'foo,          bar', count: 4 } ]

But here are a couple of examples of it not working as described:

> diff.diffWords("foo bar", "foo\n\nbar")
[
  { count: 2, value: 'foo\n' },
  { count: 1, added: true, removed: undefined, value: '\n' },
  { count: 1, value: 'bar' }
]
> diff.diffWords("( foo )", "(foo)")
[
  { count: 1, value: '(' },
  { count: 1, added: undefined, removed: true, value: ' ' },
  { count: 1, value: 'foo' },
  { count: 1, added: undefined, removed: true, value: ' ' },
  { count: 1, value: ')' }
]

The first failure case is due to changes from #217, but the second is independent of those changes.

@ExplodingCabbage
Copy link
Collaborator Author

An even more profound example of whitespace being EXTREMELY SIGNIFICANT to diffWords, in a way that produces frankly absurd results:

#160 (comment)

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

Successfully merging a pull request may close this issue.

1 participant