Skip to content

Commit 55a428f

Browse files
committed
Merge branch 'master' of https://github.com/kpdecker/jsdiff into rebaseorigin
2 parents aca6407 + 5aa8383 commit 55a428f

File tree

11 files changed

+4209
-4393
lines changed

11 files changed

+4209
-4393
lines changed

.npmignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ Gruntfile.js
1010
images
1111
index.html
1212
karma.conf.js
13-
rollup.config.js
13+
rollup.config.mjs
1414
src
1515
tasks
1616
test

.pnp.cjs

Lines changed: 2256 additions & 2453 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.yarn/install-state.gz

22.9 KB
Binary file not shown.

README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,9 @@ Broadly, jsdiff's diff functions all take an old text and a new text and perform
6060

6161
Returns a list of [change objects](#change-objects).
6262

63-
* `Diff.diffSentences(oldStr, newStr[, options])` - diffs two blocks of text, treating each sentence as a token.
63+
* `Diff.diffSentences(oldStr, newStr[, options])` - diffs two blocks of text, treating each sentence as a token. The characters `.`, `!`, and `?`, when followed by whitespace, are treated as marking the end of a sentence; nothing else is considered to mark a sentence end.
64+
65+
(For more sophisticated detection of sentence breaks, including support for non-English punctuation, consider instead tokenizing with an [`Intl.Segmenter`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Segmenter) with `granularity: 'sentence'` and passing the result to `Diff.diffArrays`.)
6466

6567
Returns a list of [change objects](#change-objects).
6668

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "diff",
3-
"version": "5.4.0",
3+
"version": "7.0.0",
44
"description": "A JavaScript text diff implementation.",
55
"keywords": [
66
"diff",

release-notes.md

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,16 @@
11
# Release Notes
22

3-
## Future breaking 6.0.0 release
3+
## 7.0.0
44

5-
[Commits](https://github.com/kpdecker/jsdiff/compare/master...v6.0.0-staging)
5+
Just a single (breaking) bugfix, undoing a behaviour change introduced accidentally in 6.0.0:
6+
7+
- [#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.
8+
9+
## 6.0.0
10+
11+
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.
12+
13+
[Commits](https://github.com/kpdecker/jsdiff/compare/v5.2.0...v6.0.0)
614

715
- [#497](https://github.com/kpdecker/jsdiff/pull/497) **`diffWords` behavior has been radically changed.** Previously, even with `ignoreWhitespace: true`, runs of whitespace were tokens, which led to unhelpful and unintuitive diffing behavior in typical texts. Specifically, even when two texts contained overlapping passages, `diffWords` would sometimes choose to delete all the words from the old text and insert them anew in their new positions in order to avoid having to delete or insert whitespace tokens. Whitespace sequences are no longer tokens as of this release, which affects both the generated diffs and the `count`s.
816

@@ -25,9 +33,9 @@
2533
- [#490](https://github.com/kpdecker/jsdiff/pull/490) **When calling diffing functions in async mode by passing a `callback` option, the diff result will now be passed as the *first* argument to the callback instead of the second.** (Previously, the first argument was never used at all and would always have value `undefined`.)
2634
- [#489](github.com/kpdecker/jsdiff/pull/489) **`this.options` no longer exists on `Diff` objects.** Instead, `options` is now passed as an argument to methods that rely on options, like `equals(left, right, options)`. This fixes a race condition in async mode, where diffing behaviour could be changed mid-execution if a concurrent usage of the same `Diff` instances overwrote its `options`.
2735
- [#518](https://github.com/kpdecker/jsdiff/pull/518) **`linedelimiters` no longer exists** on patch objects; instead, when a patch with Windows-style CRLF line endings is parsed, **the lines in `lines` will end with `\r`**. There is now a **new `autoConvertLineEndings` option, on by default**, which makes it so that when a patch with Windows-style line endings is applied to a source file with Unix style line endings, the patch gets autoconverted to use Unix-style line endings, and when a patch with Unix-style line endings is applied to a source file with Windows-style line endings, it gets autoconverted to use Windows-style line endings.
28-
- [#521](https://github.com/kpdecker/jsdiff/pull/521) **the `callback` option is now supported by `structuredPatch`, `createPatch
36+
- [#521](https://github.com/kpdecker/jsdiff/pull/521) **the `callback` option is now supported by `structuredPatch`, `createPatch`, and `createTwoFilesPatch`**
2937
- [#529](https://github.com/kpdecker/jsdiff/pull/529) **`parsePatch` can now parse patches where lines starting with `--` or `++` are deleted/inserted**; previously, there were edge cases where the parser would choke on valid patches or give wrong results.
30-
- [#530](https://github.com/kpdecker/jsdiff/pull/530) **Added `ignoreNewlineAtEof` option` to `diffLines`**
38+
- [#530](https://github.com/kpdecker/jsdiff/pull/530) **Added `ignoreNewlineAtEof` option to `diffLines`**
3139
- [#533](https://github.com/kpdecker/jsdiff/pull/533) **`applyPatch` uses an entirely new algorithm for fuzzy matching.** Differences between the old and new algorithm are as follows:
3240
* The `fuzzFactor` now indicates the maximum [*Levenshtein* distance](https://en.wikipedia.org/wiki/Levenshtein_distance) that there can be between the context shown in a hunk and the actual file content at a location where we try to apply the hunk. (Previously, it represented a maximum [*Hamming* distance](https://en.wikipedia.org/wiki/Hamming_distance), meaning that a single insertion or deletion in the source file could stop a hunk from applying even with a high `fuzzFactor`.)
3341
* A hunk containing a deletion can now only be applied in a context where the line to be deleted actually appears verbatim. (Previously, as long as enough context lines in the hunk matched, `applyPatch` would apply the hunk anyway and delete a completely different line.)
@@ -38,10 +46,10 @@
3846

3947
## v5.2.0
4048

41-
[Commits](https://github.com/kpdecker/jsdiff/compare/v5.1.0...master)
49+
[Commits](https://github.com/kpdecker/jsdiff/compare/v5.1.0...v5.2.0)
4250

4351
- [#411](https://github.com/kpdecker/jsdiff/pull/411) Big performance improvement. Previously an O(n) array-copying operation inside the innermost loop of jsdiff's base diffing code increased the overall worst-case time complexity of computing a diff from O(n²) to O(n³). This is now fixed, bringing the worst-case time complexity down to what it theoretically should be for a Myers diff implementation.
44-
- [#448](https://github.com/kpdecker/jsdiff/pull/411) Performance improvement. Diagonals whose furthest-reaching D-path would go off the edge of the edit graph are now skipped, rather than being pointlessly considered as called for by the original Myers diff algorithm. This dramatically speeds up computing diffs where the new text just appends or truncates content at the end of the old text.
52+
- [#448](https://github.com/kpdecker/jsdiff/pull/448) Performance improvement. Diagonals whose furthest-reaching D-path would go off the edge of the edit graph are now skipped, rather than being pointlessly considered as called for by the original Myers diff algorithm. This dramatically speeds up computing diffs where the new text just appends or truncates content at the end of the old text.
4553
- [#351](https://github.com/kpdecker/jsdiff/issues/351) Importing from the lib folder - e.g. `require("diff/lib/diff/word.js")` - will work again now. This had been broken for users on the latest version of Node since Node 17.5.0, which changed how Node interprets the `exports` property in jsdiff's `package.json` file.
4654
- [#344](https://github.com/kpdecker/jsdiff/issues/344) `diffLines`, `createTwoFilesPatch`, and other patch-creation methods now take an optional `stripTrailingCr: true` option which causes Windows-style `\r\n` line endings to be replaced with Unix-style `\n` line endings before calculating the diff, just like GNU `diff`'s `--strip-trailing-cr` flag.
4755
- [#451](https://github.com/kpdecker/jsdiff/pull/451) Added `diff.formatPatch`.

rollup.config.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import babel from 'rollup-plugin-babel';
2-
import pkg from './package.json' assert { type: 'json' };
2+
import pkg from './package.json' with { type: 'json' };
33

44
export default [
55
// browser-friendly UMD build

src/diff/word.js

Lines changed: 1 addition & 1 deletion
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

src/util/string.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ function overlapCount(a, b) {
9292
* Returns true if the string consistently uses Windows line endings.
9393
*/
9494
export function hasOnlyWinLineEndings(string) {
95-
return string.includes('\r\n') && !string.match(/(?<!\r)\n/);
95+
return string.includes('\r\n') && !string.startsWith('\n') && !string.match(/[^\r]\n/);
9696
}
9797

9898
/**

test/diff/word.js

Lines changed: 28 additions & 0 deletions
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)