Skip to content

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

Closed
@ExplodingCabbage

Description

@ExplodingCabbage

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.

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions