Skip to content

Commit 52d038d

Browse files
davismcpheeelastic-renovate-prod[bot]kibanamachine
authored
[8.17] Update dependency diff to v8 (main) (#220898) (#221048)
# Backport This will backport the following commits from `main` to `8.17`: - [Update dependency diff to v8 (main) (#220898)](#220898) <!--- Backport version: 9.6.6 --> ### Questions ? Please refer to the [Backport tool documentation](https://github.com/sorenlouv/backport) <!--BACKPORT [{"author":{"name":"elastic-renovate-prod[bot]","email":"174716857+elastic-renovate-prod[bot]@users.noreply.github.com"},"sourceCommit":{"committedDate":"2025-05-20T04:05:23Z","message":"Update dependency diff to v8 (main) (#220898)\n\nThis PR contains the following updates:\n\n| Package | Type | Update | Change | Pending |\n|---|---|---|---|---|\n| [diff](https://redirect.github.com/kpdecker/jsdiff) | dependencies |\nmajor | [`^7.0.0` ->\n`^8.0.0`](https://renovatebot.com/diffs/npm/diff/7.0.0/8.0.0) | `8.0.1`\n|\n\n---\n\n### Release Notes\n\n<details>\n<summary>kpdecker/jsdiff (diff)</summary>\n\n###\n[`v8.0.0`](https://redirect.github.com/kpdecker/jsdiff/blob/HEAD/release-notes.md#800)\n\n[Compare\nSource](https://redirect.github.com/kpdecker/jsdiff/compare/7.0.0...v8.0.0)\n\n- [#&#8203;580](https://redirect.github.com/kpdecker/jsdiff/pull/580)\n**Multiple tweaks to `diffSentences`**:\n- tokenization no longer takes quadratic time on pathological inputs\n(reported as a ReDOS vulnerability by Snyk); is now linear instead\n- the final sentence in the string is now handled the same by the\ntokenizer regardless of whether it has a trailing punctuation mark or\nnot. (Previously, \"foo. bar.\" tokenized to `[\"foo.\", \" \", \"bar.\"]` but\n\"foo. bar\" tokenized to `[\"foo.\", \" bar\"]` - i.e. whether the space\nbetween sentences was treated as a separate token depended upon whether\nthe final sentence had trailing punctuation or not. This was arbitrary\nand surprising; it is no longer the case.)\n- in a string that starts with a sentence end, like \"! hello.\", the \"!\"\nis now treated as a separate sentence\n- the README now correctly documents the tokenization behaviour (it was\nwrong before)\n- [#&#8203;581](https://redirect.github.com/kpdecker/jsdiff/pull/581) -\n**fixed some regex operations used for tokenization in `diffWords`\ntaking O(n^2) time** in pathological cases\n- [#&#8203;595](https://redirect.github.com/kpdecker/jsdiff/pull/595) -\n**fixed a crash in patch creation functions when handling a single hunk\nconsisting of a very large number (e.g. >130k) of lines**. (This was\ncaused by spreading indefinitely-large arrays to `.push()` using\n`.apply` or the spread operator and hitting the\nJS-implementation-specific limit on the maximum number of arguments to a\nfunction, as shown at https://stackoverflow.com/a/56809779/1709587; thus\nthe exact threshold to hit the error will depend on the environment in\nwhich you were running JsDiff.)\n- [#&#8203;596](https://redirect.github.com/kpdecker/jsdiff/pull/596) -\n**removed the `merge` function**. Previously JsDiff included an\nundocumented function called `merge` that was meant to, in some sense,\nmerge patches. It had at least a couple of serious bugs that could lead\nto it returning unambiguously wrong results, and it was difficult to\nsimply \"fix\" because it was [unclear precisely what it was meant to\ndo](https://redirect.github.com/kpdecker/jsdiff/issues/181#issuecomment-2198319542).\nFor now, the fix is to remove it entirely.\n- [#&#8203;591](https://redirect.github.com/kpdecker/jsdiff/pull/591) -\nJsDiff's source code has been rewritten in TypeScript. This change\nentails the following changes for end users:\n- **the `diff` package on npm now includes its own TypeScript type\ndefinitions**. Users who previously used the `@types/diff` npm package\nfrom DefinitelyTyped should remove that dependency when upgrading JsDiff\nto v8.\n\nNote that the transition from the DefinitelyTyped types to JsDiff's own\ntype definitions includes multiple fixes and also removes many exported\ntypes previously used for `options` arguments to diffing and\npatch-generation functions. (There are now different exported options\ntypes for abortable calls - ones with a `timeout` or `maxEditLength`\nthat may give a result of `undefined` - and non-abortable calls.) See\nthe TypeScript section of the README for some usage tips.\n\n- **The `Diff` object is now a class**. Custom extensions of `Diff`, as\ndescribed in the \"Defining custom diffing behaviors\" section of the\nREADME, can therefore now be done by writing a `class CustomDiff extends\nDiff` and overriding methods, instead of the old way based on prototype\ninheritance. (I *think* code that did things the old way should still\nwork, though!)\n\n- **`diff/lib/index.es6.js` and `diff/lib/index.mjs` no longer exist,\nand the ESM version of the library is no longer bundled into a single\nfile.**\n\n- **The `ignoreWhitespace` option for `diffWords` is no longer included\nin the type declarations**. The effect of passing `ignoreWhitespace:\ntrue` has always been to make `diffWords` just call `diffWordsWithSpace`\ninstead, which was confusing, because that behaviour doesn't seem\nproperly described as \"ignoring\" whitespace at all. The property remains\navailable to non-TypeScript applications for the sake of backwards\ncompatability, but TypeScript applications will now see a type error if\nthey try to pass `ignoreWhitespace: true` to `diffWords` and should\nchange their code to call `diffWordsWithSpace` instead.\n\n- JsDiff no longer purports to support ES3 environments. (I'm pretty\nsure it never truly did, despite claiming to in its README, since even\nthe 1.0.0 release used `Array.map` which was added in ES5.)\n- [#&#8203;601](https://redirect.github.com/kpdecker/jsdiff/pull/601) -\n**`diffJson`'s `stringifyReplacer` option behaves more like\n`JSON.stringify`'s `replacer` argument now.** In particular:\n- Each key/value pair now gets passed through the replacer once instead\nof twice\n- The `key` passed to the replacer when the top-level object is passed\nin as `value` is now `\"\"` (previously, was `undefined`), and the `key`\npassed with an array element is the array index as a string, like `\"0\"`\nor `\"1\"` (previously was whatever the key for the entire array was).\nBoth the new behaviours match that of `JSON.stringify`.\n- [#&#8203;602](https://redirect.github.com/kpdecker/jsdiff/pull/602) -\n**diffing functions now consistently return `undefined` when called in\nasync mode** (i.e. with a callback). Previously, there was an odd quirk\nwhere they would return `true` if the strings being diffed were equal\nand `undefined` otherwise.\n\n</details>\n\n---\n\n### Configuration\n\n📅 **Schedule**: Branch creation - At any time (no schedule defined),\nAutomerge - At any time (no schedule defined).\n\n🚦 **Automerge**: Disabled by config. Please merge this manually once you\nare satisfied.\n\n♻ **Rebasing**: Whenever PR becomes conflicted, or you tick the\nrebase/retry checkbox.\n\n🔕 **Ignore**: Close this PR and you won't be reminded about this update\nagain.\n\n---\n\n- [ ] If you want to rebase/retry this PR, check\nthis box\n\n---\n\nThis PR has been generated by [Renovate\nBot](https://redirect.github.com/renovatebot/renovate).\n\n\n\n---------\n\nCo-authored-by: elastic-renovate-prod[bot] <174716857+elastic-renovate-prod[bot]@users.noreply.github.com>\nCo-authored-by: Davis McPhee <[email protected]>","sha":"dbd586662598348af0c193b354f3317bed835751","branchLabelMapping":{"^v9.1.0$":"main","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["release_note:skip","Team:DataDiscovery","backport:all-open","v9.1.0"],"title":"Update dependency diff to v8 (main)","number":220898,"url":"https://github.com/elastic/kibana/pull/220898","mergeCommit":{"message":"Update dependency diff to v8 (main) (#220898)\n\nThis PR contains the following updates:\n\n| Package | Type | Update | Change | Pending |\n|---|---|---|---|---|\n| [diff](https://redirect.github.com/kpdecker/jsdiff) | dependencies |\nmajor | [`^7.0.0` ->\n`^8.0.0`](https://renovatebot.com/diffs/npm/diff/7.0.0/8.0.0) | `8.0.1`\n|\n\n---\n\n### Release Notes\n\n<details>\n<summary>kpdecker/jsdiff (diff)</summary>\n\n###\n[`v8.0.0`](https://redirect.github.com/kpdecker/jsdiff/blob/HEAD/release-notes.md#800)\n\n[Compare\nSource](https://redirect.github.com/kpdecker/jsdiff/compare/7.0.0...v8.0.0)\n\n- [#&#8203;580](https://redirect.github.com/kpdecker/jsdiff/pull/580)\n**Multiple tweaks to `diffSentences`**:\n- tokenization no longer takes quadratic time on pathological inputs\n(reported as a ReDOS vulnerability by Snyk); is now linear instead\n- the final sentence in the string is now handled the same by the\ntokenizer regardless of whether it has a trailing punctuation mark or\nnot. (Previously, \"foo. bar.\" tokenized to `[\"foo.\", \" \", \"bar.\"]` but\n\"foo. bar\" tokenized to `[\"foo.\", \" bar\"]` - i.e. whether the space\nbetween sentences was treated as a separate token depended upon whether\nthe final sentence had trailing punctuation or not. This was arbitrary\nand surprising; it is no longer the case.)\n- in a string that starts with a sentence end, like \"! hello.\", the \"!\"\nis now treated as a separate sentence\n- the README now correctly documents the tokenization behaviour (it was\nwrong before)\n- [#&#8203;581](https://redirect.github.com/kpdecker/jsdiff/pull/581) -\n**fixed some regex operations used for tokenization in `diffWords`\ntaking O(n^2) time** in pathological cases\n- [#&#8203;595](https://redirect.github.com/kpdecker/jsdiff/pull/595) -\n**fixed a crash in patch creation functions when handling a single hunk\nconsisting of a very large number (e.g. >130k) of lines**. (This was\ncaused by spreading indefinitely-large arrays to `.push()` using\n`.apply` or the spread operator and hitting the\nJS-implementation-specific limit on the maximum number of arguments to a\nfunction, as shown at https://stackoverflow.com/a/56809779/1709587; thus\nthe exact threshold to hit the error will depend on the environment in\nwhich you were running JsDiff.)\n- [#&#8203;596](https://redirect.github.com/kpdecker/jsdiff/pull/596) -\n**removed the `merge` function**. Previously JsDiff included an\nundocumented function called `merge` that was meant to, in some sense,\nmerge patches. It had at least a couple of serious bugs that could lead\nto it returning unambiguously wrong results, and it was difficult to\nsimply \"fix\" because it was [unclear precisely what it was meant to\ndo](https://redirect.github.com/kpdecker/jsdiff/issues/181#issuecomment-2198319542).\nFor now, the fix is to remove it entirely.\n- [#&#8203;591](https://redirect.github.com/kpdecker/jsdiff/pull/591) -\nJsDiff's source code has been rewritten in TypeScript. This change\nentails the following changes for end users:\n- **the `diff` package on npm now includes its own TypeScript type\ndefinitions**. Users who previously used the `@types/diff` npm package\nfrom DefinitelyTyped should remove that dependency when upgrading JsDiff\nto v8.\n\nNote that the transition from the DefinitelyTyped types to JsDiff's own\ntype definitions includes multiple fixes and also removes many exported\ntypes previously used for `options` arguments to diffing and\npatch-generation functions. (There are now different exported options\ntypes for abortable calls - ones with a `timeout` or `maxEditLength`\nthat may give a result of `undefined` - and non-abortable calls.) See\nthe TypeScript section of the README for some usage tips.\n\n- **The `Diff` object is now a class**. Custom extensions of `Diff`, as\ndescribed in the \"Defining custom diffing behaviors\" section of the\nREADME, can therefore now be done by writing a `class CustomDiff extends\nDiff` and overriding methods, instead of the old way based on prototype\ninheritance. (I *think* code that did things the old way should still\nwork, though!)\n\n- **`diff/lib/index.es6.js` and `diff/lib/index.mjs` no longer exist,\nand the ESM version of the library is no longer bundled into a single\nfile.**\n\n- **The `ignoreWhitespace` option for `diffWords` is no longer included\nin the type declarations**. The effect of passing `ignoreWhitespace:\ntrue` has always been to make `diffWords` just call `diffWordsWithSpace`\ninstead, which was confusing, because that behaviour doesn't seem\nproperly described as \"ignoring\" whitespace at all. The property remains\navailable to non-TypeScript applications for the sake of backwards\ncompatability, but TypeScript applications will now see a type error if\nthey try to pass `ignoreWhitespace: true` to `diffWords` and should\nchange their code to call `diffWordsWithSpace` instead.\n\n- JsDiff no longer purports to support ES3 environments. (I'm pretty\nsure it never truly did, despite claiming to in its README, since even\nthe 1.0.0 release used `Array.map` which was added in ES5.)\n- [#&#8203;601](https://redirect.github.com/kpdecker/jsdiff/pull/601) -\n**`diffJson`'s `stringifyReplacer` option behaves more like\n`JSON.stringify`'s `replacer` argument now.** In particular:\n- Each key/value pair now gets passed through the replacer once instead\nof twice\n- The `key` passed to the replacer when the top-level object is passed\nin as `value` is now `\"\"` (previously, was `undefined`), and the `key`\npassed with an array element is the array index as a string, like `\"0\"`\nor `\"1\"` (previously was whatever the key for the entire array was).\nBoth the new behaviours match that of `JSON.stringify`.\n- [#&#8203;602](https://redirect.github.com/kpdecker/jsdiff/pull/602) -\n**diffing functions now consistently return `undefined` when called in\nasync mode** (i.e. with a callback). Previously, there was an odd quirk\nwhere they would return `true` if the strings being diffed were equal\nand `undefined` otherwise.\n\n</details>\n\n---\n\n### Configuration\n\n📅 **Schedule**: Branch creation - At any time (no schedule defined),\nAutomerge - At any time (no schedule defined).\n\n🚦 **Automerge**: Disabled by config. Please merge this manually once you\nare satisfied.\n\n♻ **Rebasing**: Whenever PR becomes conflicted, or you tick the\nrebase/retry checkbox.\n\n🔕 **Ignore**: Close this PR and you won't be reminded about this update\nagain.\n\n---\n\n- [ ] If you want to rebase/retry this PR, check\nthis box\n\n---\n\nThis PR has been generated by [Renovate\nBot](https://redirect.github.com/renovatebot/renovate).\n\n\n\n---------\n\nCo-authored-by: elastic-renovate-prod[bot] <174716857+elastic-renovate-prod[bot]@users.noreply.github.com>\nCo-authored-by: Davis McPhee <[email protected]>","sha":"dbd586662598348af0c193b354f3317bed835751"}},"sourceBranch":"main","suggestedTargetBranches":[],"targetPullRequestStates":[{"branch":"main","label":"v9.1.0","branchLabelMappingKey":"^v9.1.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/220898","number":220898,"mergeCommit":{"message":"Update dependency diff to v8 (main) (#220898)\n\nThis PR contains the following updates:\n\n| Package | Type | Update | Change | Pending |\n|---|---|---|---|---|\n| [diff](https://redirect.github.com/kpdecker/jsdiff) | dependencies |\nmajor | [`^7.0.0` ->\n`^8.0.0`](https://renovatebot.com/diffs/npm/diff/7.0.0/8.0.0) | `8.0.1`\n|\n\n---\n\n### Release Notes\n\n<details>\n<summary>kpdecker/jsdiff (diff)</summary>\n\n###\n[`v8.0.0`](https://redirect.github.com/kpdecker/jsdiff/blob/HEAD/release-notes.md#800)\n\n[Compare\nSource](https://redirect.github.com/kpdecker/jsdiff/compare/7.0.0...v8.0.0)\n\n- [#&#8203;580](https://redirect.github.com/kpdecker/jsdiff/pull/580)\n**Multiple tweaks to `diffSentences`**:\n- tokenization no longer takes quadratic time on pathological inputs\n(reported as a ReDOS vulnerability by Snyk); is now linear instead\n- the final sentence in the string is now handled the same by the\ntokenizer regardless of whether it has a trailing punctuation mark or\nnot. (Previously, \"foo. bar.\" tokenized to `[\"foo.\", \" \", \"bar.\"]` but\n\"foo. bar\" tokenized to `[\"foo.\", \" bar\"]` - i.e. whether the space\nbetween sentences was treated as a separate token depended upon whether\nthe final sentence had trailing punctuation or not. This was arbitrary\nand surprising; it is no longer the case.)\n- in a string that starts with a sentence end, like \"! hello.\", the \"!\"\nis now treated as a separate sentence\n- the README now correctly documents the tokenization behaviour (it was\nwrong before)\n- [#&#8203;581](https://redirect.github.com/kpdecker/jsdiff/pull/581) -\n**fixed some regex operations used for tokenization in `diffWords`\ntaking O(n^2) time** in pathological cases\n- [#&#8203;595](https://redirect.github.com/kpdecker/jsdiff/pull/595) -\n**fixed a crash in patch creation functions when handling a single hunk\nconsisting of a very large number (e.g. >130k) of lines**. (This was\ncaused by spreading indefinitely-large arrays to `.push()` using\n`.apply` or the spread operator and hitting the\nJS-implementation-specific limit on the maximum number of arguments to a\nfunction, as shown at https://stackoverflow.com/a/56809779/1709587; thus\nthe exact threshold to hit the error will depend on the environment in\nwhich you were running JsDiff.)\n- [#&#8203;596](https://redirect.github.com/kpdecker/jsdiff/pull/596) -\n**removed the `merge` function**. Previously JsDiff included an\nundocumented function called `merge` that was meant to, in some sense,\nmerge patches. It had at least a couple of serious bugs that could lead\nto it returning unambiguously wrong results, and it was difficult to\nsimply \"fix\" because it was [unclear precisely what it was meant to\ndo](https://redirect.github.com/kpdecker/jsdiff/issues/181#issuecomment-2198319542).\nFor now, the fix is to remove it entirely.\n- [#&#8203;591](https://redirect.github.com/kpdecker/jsdiff/pull/591) -\nJsDiff's source code has been rewritten in TypeScript. This change\nentails the following changes for end users:\n- **the `diff` package on npm now includes its own TypeScript type\ndefinitions**. Users who previously used the `@types/diff` npm package\nfrom DefinitelyTyped should remove that dependency when upgrading JsDiff\nto v8.\n\nNote that the transition from the DefinitelyTyped types to JsDiff's own\ntype definitions includes multiple fixes and also removes many exported\ntypes previously used for `options` arguments to diffing and\npatch-generation functions. (There are now different exported options\ntypes for abortable calls - ones with a `timeout` or `maxEditLength`\nthat may give a result of `undefined` - and non-abortable calls.) See\nthe TypeScript section of the README for some usage tips.\n\n- **The `Diff` object is now a class**. Custom extensions of `Diff`, as\ndescribed in the \"Defining custom diffing behaviors\" section of the\nREADME, can therefore now be done by writing a `class CustomDiff extends\nDiff` and overriding methods, instead of the old way based on prototype\ninheritance. (I *think* code that did things the old way should still\nwork, though!)\n\n- **`diff/lib/index.es6.js` and `diff/lib/index.mjs` no longer exist,\nand the ESM version of the library is no longer bundled into a single\nfile.**\n\n- **The `ignoreWhitespace` option for `diffWords` is no longer included\nin the type declarations**. The effect of passing `ignoreWhitespace:\ntrue` has always been to make `diffWords` just call `diffWordsWithSpace`\ninstead, which was confusing, because that behaviour doesn't seem\nproperly described as \"ignoring\" whitespace at all. The property remains\navailable to non-TypeScript applications for the sake of backwards\ncompatability, but TypeScript applications will now see a type error if\nthey try to pass `ignoreWhitespace: true` to `diffWords` and should\nchange their code to call `diffWordsWithSpace` instead.\n\n- JsDiff no longer purports to support ES3 environments. (I'm pretty\nsure it never truly did, despite claiming to in its README, since even\nthe 1.0.0 release used `Array.map` which was added in ES5.)\n- [#&#8203;601](https://redirect.github.com/kpdecker/jsdiff/pull/601) -\n**`diffJson`'s `stringifyReplacer` option behaves more like\n`JSON.stringify`'s `replacer` argument now.** In particular:\n- Each key/value pair now gets passed through the replacer once instead\nof twice\n- The `key` passed to the replacer when the top-level object is passed\nin as `value` is now `\"\"` (previously, was `undefined`), and the `key`\npassed with an array element is the array index as a string, like `\"0\"`\nor `\"1\"` (previously was whatever the key for the entire array was).\nBoth the new behaviours match that of `JSON.stringify`.\n- [#&#8203;602](https://redirect.github.com/kpdecker/jsdiff/pull/602) -\n**diffing functions now consistently return `undefined` when called in\nasync mode** (i.e. with a callback). Previously, there was an odd quirk\nwhere they would return `true` if the strings being diffed were equal\nand `undefined` otherwise.\n\n</details>\n\n---\n\n### Configuration\n\n📅 **Schedule**: Branch creation - At any time (no schedule defined),\nAutomerge - At any time (no schedule defined).\n\n🚦 **Automerge**: Disabled by config. Please merge this manually once you\nare satisfied.\n\n♻ **Rebasing**: Whenever PR becomes conflicted, or you tick the\nrebase/retry checkbox.\n\n🔕 **Ignore**: Close this PR and you won't be reminded about this update\nagain.\n\n---\n\n- [ ] If you want to rebase/retry this PR, check\nthis box\n\n---\n\nThis PR has been generated by [Renovate\nBot](https://redirect.github.com/renovatebot/renovate).\n\n\n\n---------\n\nCo-authored-by: elastic-renovate-prod[bot] <174716857+elastic-renovate-prod[bot]@users.noreply.github.com>\nCo-authored-by: Davis McPhee <[email protected]>","sha":"dbd586662598348af0c193b354f3317bed835751"}},{"url":"https://github.com/elastic/kibana/pull/220946","number":220946,"branch":"9.0","state":"OPEN"}]}] BACKPORT--> --------- Co-authored-by: elastic-renovate-prod[bot] <174716857+elastic-renovate-prod[bot]@users.noreply.github.com> Co-authored-by: kibanamachine <[email protected]>
1 parent 04d962b commit 52d038d

File tree

6 files changed

+83
-41
lines changed

6 files changed

+83
-41
lines changed

package.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1120,7 +1120,7 @@
11201120
"deep-freeze-strict": "^1.1.1",
11211121
"deepmerge": "^4.3.1",
11221122
"del": "^6.1.0",
1123-
"diff": "^5.1.0",
1123+
"diff": "^8.0.0",
11241124
"dotenv": "^16.4.5",
11251125
"elastic-apm-node": "^4.13.0",
11261126
"email-addresses": "^5.0.0",
@@ -1558,7 +1558,6 @@
15581558
"@types/dagre": "^0.7.47",
15591559
"@types/dedent": "^0.7.0",
15601560
"@types/deep-freeze-strict": "^1.1.0",
1561-
"@types/diff": "^5.0.8",
15621561
"@types/ejs": "^3.0.6",
15631562
"@types/enzyme": "^3.10.12",
15641563
"@types/eslint": "^8.44.2",

packages/kbn-unified-data-table/src/components/compare_documents/hooks/__snapshots__/use_comparison_cell_value.test.tsx.snap

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

packages/kbn-unified-data-table/src/components/compare_documents/hooks/calculate_diff.test.ts

Lines changed: 63 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -20,63 +20,81 @@ describe('calculateDiff', () => {
2020
expect(result).toMatchInlineSnapshot(`
2121
Array [
2222
Object {
23+
"added": false,
2324
"count": 5,
25+
"removed": false,
2426
"value": "This ",
2527
},
2628
Object {
2729
"added": true,
2830
"count": 4,
29-
"removed": undefined,
31+
"removed": false,
3032
"value": "one ",
3133
},
3234
Object {
35+
"added": false,
3336
"count": 5,
37+
"removed": false,
3438
"value": "is a ",
3539
},
3640
Object {
37-
"added": true,
38-
"count": 10,
39-
"removed": undefined,
40-
"value": "different ",
41-
},
42-
Object {
41+
"added": false,
4342
"count": 1,
43+
"removed": true,
4444
"value": "m",
4545
},
4646
Object {
47-
"added": undefined,
47+
"added": true,
48+
"count": 4,
49+
"removed": false,
50+
"value": "diff",
51+
},
52+
Object {
53+
"added": false,
4854
"count": 1,
49-
"removed": true,
55+
"removed": false,
5056
"value": "e",
5157
},
5258
Object {
59+
"added": true,
60+
"count": 6,
61+
"removed": false,
62+
"value": "rent m",
63+
},
64+
Object {
65+
"added": false,
5366
"count": 1,
67+
"removed": false,
5468
"value": "s",
5569
},
5670
Object {
57-
"added": undefined,
71+
"added": false,
5872
"count": 2,
5973
"removed": true,
6074
"value": "sa",
6175
},
6276
Object {
77+
"added": false,
6378
"count": 1,
79+
"removed": false,
6480
"value": "g",
6581
},
6682
Object {
67-
"added": undefined,
83+
"added": false,
6884
"count": 1,
6985
"removed": true,
7086
"value": "e",
7187
},
7288
Object {
89+
"added": false,
7390
"count": 4,
91+
"removed": false,
7492
"value": " val",
7593
},
7694
Object {
7795
"added": true,
7896
"count": 2,
79-
"removed": undefined,
97+
"removed": false,
8098
"value": "ue",
8199
},
82100
]
@@ -88,45 +106,51 @@ describe('calculateDiff', () => {
88106
expect(result).toMatchInlineSnapshot(`
89107
Array [
90108
Object {
109+
"added": false,
91110
"count": 2,
111+
"removed": false,
92112
"value": "This ",
93113
},
94114
Object {
95115
"added": true,
96116
"count": 2,
97-
"removed": undefined,
117+
"removed": false,
98118
"value": "one ",
99119
},
100120
Object {
121+
"added": false,
101122
"count": 4,
123+
"removed": false,
102124
"value": "is a ",
103125
},
104126
Object {
105-
"added": undefined,
127+
"added": false,
106128
"count": 1,
107129
"removed": true,
108130
"value": "message",
109131
},
110132
Object {
111133
"added": true,
112134
"count": 1,
113-
"removed": undefined,
135+
"removed": false,
114136
"value": "different",
115137
},
116138
Object {
139+
"added": false,
117140
"count": 1,
141+
"removed": false,
118142
"value": " ",
119143
},
120144
Object {
121-
"added": undefined,
145+
"added": false,
122146
"count": 1,
123147
"removed": true,
124148
"value": "val",
125149
},
126150
Object {
127151
"added": true,
128152
"count": 3,
129-
"removed": undefined,
153+
"removed": false,
130154
"value": "msg value",
131155
},
132156
]
@@ -138,15 +162,15 @@ describe('calculateDiff', () => {
138162
expect(result).toMatchInlineSnapshot(`
139163
Array [
140164
Object {
141-
"added": undefined,
165+
"added": false,
142166
"count": 1,
143167
"removed": true,
144168
"value": "This is a message val",
145169
},
146170
Object {
147171
"added": true,
148172
"count": 1,
149-
"removed": undefined,
173+
"removed": false,
150174
"value": "This one is a different msg value",
151175
},
152176
]
@@ -162,31 +186,37 @@ describe('calculateDiff', () => {
162186
expect(result).toMatchInlineSnapshot(`
163187
Array [
164188
Object {
189+
"added": false,
165190
"count": 1,
191+
"removed": false,
166192
"value": "[
167193
",
168194
},
169195
Object {
170-
"added": undefined,
196+
"added": false,
171197
"count": 1,
172198
"removed": true,
173199
"value": " \\"gif\\",
174200
",
175201
},
176202
Object {
203+
"added": false,
177204
"count": 1,
205+
"removed": false,
178206
"value": " \\"png\\",
179207
",
180208
},
181209
Object {
182210
"added": true,
183211
"count": 1,
184-
"removed": undefined,
212+
"removed": false,
185213
"value": " \\"jpg\\"
186214
",
187215
},
188216
Object {
217+
"added": false,
189218
"count": 1,
219+
"removed": false,
190220
"value": "]",
191221
},
192222
]
@@ -203,12 +233,14 @@ describe('calculateDiff', () => {
203233
expect(result).toMatchInlineSnapshot(`
204234
Array [
205235
Object {
236+
"added": false,
206237
"count": 1,
238+
"removed": false,
207239
"value": "[
208240
",
209241
},
210242
Object {
211-
"added": undefined,
243+
"added": false,
212244
"count": 1,
213245
"removed": true,
214246
"value": " \\"single value\\"
@@ -217,13 +249,15 @@ describe('calculateDiff', () => {
217249
Object {
218250
"added": true,
219251
"count": 2,
220-
"removed": undefined,
252+
"removed": false,
221253
"value": " \\"multiple\\",
222254
\\"values\\"
223255
",
224256
},
225257
Object {
258+
"added": false,
226259
"count": 1,
260+
"removed": false,
227261
"value": "]",
228262
},
229263
]
@@ -236,12 +270,14 @@ describe('calculateDiff', () => {
236270
expect(result2).toMatchInlineSnapshot(`
237271
Array [
238272
Object {
273+
"added": false,
239274
"count": 1,
275+
"removed": false,
240276
"value": "[
241277
",
242278
},
243279
Object {
244-
"added": undefined,
280+
"added": false,
245281
"count": 2,
246282
"removed": true,
247283
"value": " \\"multiple\\",
@@ -251,12 +287,14 @@ describe('calculateDiff', () => {
251287
Object {
252288
"added": true,
253289
"count": 1,
254-
"removed": undefined,
290+
"removed": false,
255291
"value": " \\"single value\\"
256292
",
257293
},
258294
Object {
295+
"added": false,
259296
"count": 1,
297+
"removed": false,
260298
"value": "]",
261299
},
262300
]

packages/kbn-unified-data-table/src/components/compare_documents/hooks/calculate_diff.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
* License v3.0 only", or the "Server Side Public License, v 1".
88
*/
99

10-
import { diffChars, diffJson, diffLines, diffWords } from 'diff';
10+
import { diffChars, diffJson, diffLines, diffWordsWithSpace } from 'diff';
1111
import type { DocumentDiffMode } from '../types';
1212

1313
export interface CalculateDiffProps {
@@ -38,11 +38,11 @@ export const calculateDiff = ({ diffMode, baseValue, comparisonValue }: Calculat
3838
}
3939

4040
if (diffMode === 'words') {
41-
return diffWords(formattedBaseValue, formattedComparisonValue, { ignoreWhitespace: false });
41+
return diffWordsWithSpace(formattedBaseValue, formattedComparisonValue);
4242
}
4343

4444
return baseValueIsJson && comparisonValueIsJson
45-
? diffJson(formattedBaseValue, formattedComparisonValue, { ignoreWhitespace: false })
45+
? diffJson(formattedBaseValue, formattedComparisonValue)
4646
: diffLines(formattedBaseValue, formattedComparisonValue, { ignoreWhitespace: false });
4747
};
4848

packages/kbn-unified-data-table/src/components/compare_documents/hooks/use_comparison_cell_value.test.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -277,8 +277,8 @@ describe('useComparisonCellValue', () => {
277277
expect(comparisonCell1.getCell()).not.toHaveClass(BASE_CELL_CLASS);
278278
expect(comparisonCell1.getCell()).not.toHaveClass(MATCH_CELL_CLASS);
279279
expect(comparisonCell1.getCell()).not.toHaveClass(DIFF_CELL_CLASS);
280-
expect(comparisonCell1.getAllSegments()).toHaveLength(12);
281-
expect(comparisonCell1.getAddedSegments()).toHaveLength(3);
280+
expect(comparisonCell1.getAllSegments()).toHaveLength(13);
281+
expect(comparisonCell1.getAddedSegments()).toHaveLength(4);
282282
expect(comparisonCell1.getRemovedSegments()).toHaveLength(3);
283283
expect(comparisonCell1.getCell()).toMatchSnapshot();
284284
const comparisonCell2 = renderComparisonCell({

yarn.lock

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11459,11 +11459,6 @@
1145911459
resolved "https://registry.yarnpkg.com/@types/deep-freeze-strict/-/deep-freeze-strict-1.1.0.tgz#447a6a2576191344aa42310131dd3df5c41492c4"
1146011460
integrity sha1-RHpqJXYZE0SqQjEBMd099cQUksQ=
1146111461

11462-
"@types/diff@^5.0.8":
11463-
version "5.0.8"
11464-
resolved "https://registry.yarnpkg.com/@types/diff/-/diff-5.0.8.tgz#28dc501cc3e7c62d4c5d096afe20755170acf276"
11465-
integrity sha512-kR0gRf0wMwpxQq6ME5s+tWk9zVCfJUl98eRkD05HWWRbhPB/eu4V1IbyZAsvzC1Gn4znBJ0HN01M4DGXdBEV8Q==
11466-
1146711462
"@types/ejs@^3.0.6":
1146811463
version "3.0.6"
1146911464
resolved "https://registry.yarnpkg.com/@types/ejs/-/ejs-3.0.6.tgz#aca442289df623bfa8e47c23961f0357847b83fe"
@@ -17490,6 +17485,11 @@ diff@^5.0.0, diff@^5.1.0, diff@^5.2.0:
1749017485
resolved "https://registry.yarnpkg.com/diff/-/diff-5.2.0.tgz#26ded047cd1179b78b9537d5ef725503ce1ae531"
1749117486
integrity sha512-uIFDxqpRZGZ6ThOk84hEfqWoHx2devRFvpTZcTHur85vImfaxUbTW9Ryh4CpCuDnToOP1CEtXKIgytHBPVff5A==
1749217487

17488+
diff@^8.0.0:
17489+
version "8.0.1"
17490+
resolved "https://registry.yarnpkg.com/diff/-/diff-8.0.1.tgz#1562531dbca460fe5be98a026412996ccab1abd5"
17491+
integrity sha512-rEaM3KmVm78zE3dFZaop3aCQa2MTm+T4kcigUFLVU/KbOYdiY6JnL2g2puOYnct3QFw9pjZadaCbCZ1O8ArMlQ==
17492+
1749317493
diffie-hellman@^5.0.3:
1749417494
version "5.0.3"
1749517495
resolved "https://registry.yarnpkg.com/diffie-hellman/-/diffie-hellman-5.0.3.tgz#40e8ee98f55a2149607146921c63e1ae5f3d2875"

0 commit comments

Comments
 (0)