Skip to content

Commit 7d113b6

Browse files
Fix diffWords treating numbers and underscores as not being word characters (#554)
* Add test for bug #553 * Fix bug * Add release notes
1 parent f9972d6 commit 7d113b6

File tree

3 files changed

+33
-1
lines changed

3 files changed

+33
-1
lines changed

release-notes.md

+4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# Release Notes
22

3+
## Future 7.0.0 release
4+
5+
- [#554](https://github.com/kpdecker/jsdiff/pull/554) **`diffWords` treats numbers and underscores as word characters again.** This behaviour was broken in v6.0.0.
6+
37
## 6.0.0
48

59
This is a release containing many, *many* breaking changes. The objective of this release was to carry out a mass fix, in one go, of all the open bugs and design problems that required breaking changes to fix. A substantial, but exhaustive, changelog is below.

src/diff/word.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ import { longestCommonPrefix, longestCommonSuffix, replacePrefix, replaceSuffix,
1919
// - U+02DC ˜ ˜ Small Tilde
2020
// - U+02DD ˝ ˝ Double Acute Accent
2121
// Latin Extended Additional, 1E00–1EFF
22-
const extendedWordChars = 'a-zA-Z\\u{C0}-\\u{FF}\\u{D8}-\\u{F6}\\u{F8}-\\u{2C6}\\u{2C8}-\\u{2D7}\\u{2DE}-\\u{2FF}\\u{1E00}-\\u{1EFF}';
22+
const extendedWordChars = 'a-zA-Z0-9_\\u{C0}-\\u{FF}\\u{D8}-\\u{F6}\\u{F8}-\\u{2C6}\\u{2C8}-\\u{2D7}\\u{2DE}-\\u{2FF}\\u{1E00}-\\u{1EFF}';
2323

2424
// Each token is one of the following:
2525
// - A punctuation mark plus the surrounding whitespace

test/diff/word.js

+28
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,34 @@ describe('WordDiff', function() {
3131
'.'
3232
]);
3333
});
34+
35+
// Test for bug reported at https://github.com/kpdecker/jsdiff/issues/553
36+
it('should treat numbers as part of a word if not separated by whitespace or punctuation', () => {
37+
expect(
38+
wordDiff.tokenize(
39+
'Tea Too, also known as T2, had revenue of 57m AUD in 2012-13.'
40+
)
41+
).to.deep.equal([
42+
'Tea ',
43+
' Too',
44+
', ',
45+
' also ',
46+
' known ',
47+
' as ',
48+
' T2',
49+
', ',
50+
' had ',
51+
' revenue ',
52+
' of ',
53+
' 57m ',
54+
' AUD ',
55+
' in ',
56+
' 2012',
57+
'-',
58+
'13',
59+
'.'
60+
]);
61+
});
3462
});
3563

3664
describe('#diffWords', function() {

0 commit comments

Comments
 (0)