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

Update @elastic/kibana-data-discovery dependencies (main) #202622

Merged

Conversation

elastic-renovate-prod[bot]
Copy link
Contributor

@elastic-renovate-prod elastic-renovate-prod bot commented Dec 3, 2024

This PR contains the following updates:

Package Type Update Change
@types/diff (source) devDependencies major ^5.0.8 -> ^6.0.0
diff dependencies major ^5.1.0 -> ^7.0.0
fastest-levenshtein dependencies patch ^1.0.12 -> ^1.0.16

Release Notes

kpdecker/jsdiff (diff)

v7.0.0

Compare Source

Just a single (breaking) bugfix, undoing a behaviour change introduced accidentally in 6.0.0:

  • #​554 diffWords treats numbers and underscores as word characters again. This behaviour was broken in v6.0.0.

v6.0.0

Compare Source

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.

Commits

  • #​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 counts.

    Runs of whitespace are still tokens in diffWordsWithSpace.

    As part of the changes to diffWords, a new .postProcess method has been added on the base Diff type, which can be overridden in custom Diff implementations.

    diffLines with ignoreWhitespace: true will no longer ignore the insertion or deletion of entire extra lines of whitespace at the end of the text. Previously, these would not show up as insertions or deletions, as a side effect of a hack in the base diffing algorithm meant to help ignore whitespace in diffWords. More generally, the undocumented special handling in the core algorithm for ignored terminals has been removed entirely. (This special case behavior used to rewrite the final two change objects in a scenario where the final change object was an addition or deletion and its value was treated as equal to the empty string when compared using the diff object's .equals method.)

  • #​500 diffChars now diffs Unicode code points instead of UTF-16 code units.

  • #​508 parsePatch now always runs in what was previously "strict" mode; the undocumented strict option has been removed. Previously, by default, parsePatch (and other patch functions that use it under the hood to parse patches) would accept a patch where the line counts in the headers were inconsistent with the actual patch content - e.g. where a hunk started with the header @@​ -1,3 +1,6 @​@​, indicating that the content below spanned 3 lines in the old file and 6 lines in the new file, but then the actual content below the header consisted of some different number of lines, say 10 lines of context, 5 deletions, and 1 insertion. Actually trying to work with these patches using applyPatch or merge, however, would produce incorrect results instead of just ignoring the incorrect headers, making this "feature" more of a trap than something actually useful. It's been ripped out, and now we are always "strict" and will reject patches where the line counts in the headers aren't consistent with the actual patch content.

  • #​435 Fix parsePatch handling of control characters. parsePatch used to interpret various unusual control characters - namely vertical tabs, form feeds, lone carriage returns without a line feed, and EBCDIC NELs - as line breaks when parsing a patch file. This was inconsistent with the behavior of both JsDiff's own diffLines method and also the Unix diff and patch utils, which all simply treat those control characters as ordinary characters. The result of this discrepancy was that some well-formed patches - produced either by diff or by JsDiff itself and handled properly by the patch util - would be wrongly parsed by parsePatch, with the effect that it would disregard the remainder of a hunk after encountering one of these control characters.

  • #​439 Prefer diffs that order deletions before insertions. When faced with a choice between two diffs with an equal total edit distance, the Myers diff algorithm generally prefers one that does deletions before insertions rather than insertions before deletions. For instance, when diffing abcd against acbd, it will prefer a diff that says to delete the b and then insert a new b after the c, over a diff that says to insert a c before the b and then delete the existing c. JsDiff deviated from the published Myers algorithm in a way that led to it having the opposite preference in many cases, including that example. This is now fixed, meaning diffs output by JsDiff will more accurately reflect what the published Myers diff algorithm would output.

  • #​455 The added and removed properties of change objects are now guaranteed to be set to a boolean value. (Previously, they would be set to undefined or omitted entirely instead of setting them to false.)

  • #​464 Specifying {maxEditLength: 0} now sets a max edit length of 0 instead of no maximum.

  • #​460 Added oneChangePerToken option.

  • #​467 Consistent ordering of arguments to comparator(left, right). Values from the old array will now consistently be passed as the first argument (left) and values from the new array as the second argument (right). Previously this was almost (but not quite) always the other way round.

  • #​480 Passing maxEditLength to createPatch & createTwoFilesPatch now works properly (i.e. returns undefined if the max edit distance is exceeded; previous behavior was to crash with a TypeError if the edit distance was exceeded).

  • #​486 The ignoreWhitespace option of diffLines behaves more sensibly now. values in returned change objects now include leading/trailing whitespace even when ignoreWhitespace is used, just like how with ignoreCase the values still reflect the case of one of the original texts instead of being all-lowercase. ignoreWhitespace is also now compatible with newlineIsToken. Finally, diffTrimmedLines is deprecated (and removed from the docs) in favour of using diffLines with ignoreWhitespace: true; the two are, and always have been, equivalent.

  • #​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.)

  • #​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.

  • #​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.

  • #​521 the callback option is now supported by structuredPatch, createPatch, and createTwoFilesPatch

  • #​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.

  • #​530 Added ignoreNewlineAtEof option to diffLines

  • #​533 applyPatch uses an entirely new algorithm for fuzzy matching. Differences between the old and new algorithm are as follows:

    • The fuzzFactor now indicates the maximum 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, meaning that a single insertion or deletion in the source file could stop a hunk from applying even with a high fuzzFactor.)
    • 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.)
    • The context line immediately before and immediately after an insertion must match exactly between the hunk and the file for a hunk to apply. (Previously this was not required.)
  • #​535 A bug in patch generation functions is now fixed that would sometimes previously cause \ No newline at end of file to appear in the wrong place in the generated patch, resulting in the patch being invalid.

  • #​535 Passing newlineIsToken: true to patch-generation functions is no longer allowed. (Passing it to diffLines is still supported - it's only functions like createPatch where passing newlineIsToken is now an error.) Allowing it to be passed never really made sense, since in cases where the option had any effect on the output at all, the effect tended to be causing a garbled patch to be created that couldn't actually be applied to the source file.

  • #​539 diffWords now takes an optional intlSegmenter option which should be an Intl.Segmenter with word-level granularity. This provides better tokenization of text into words than the default behaviour, even for English but especially for some other languages for which the default behaviour is poor.

v5.2.0

Compare Source

Commits

  • #​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.
  • #​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.
  • #​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.
  • #​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.
  • #​451 Added diff.formatPatch.
  • #​450 Added diff.reversePatch.
  • #​478 Added timeout option.
ka-weihe/fastest-levenshtein (fastest-levenshtein)

v1.0.16

Compare Source

v1.0.15

Compare Source

v1.0.14

Compare Source

v1.0.13

Compare Source


Configuration

📅 Schedule: Branch creation - At any time (no schedule defined), Automerge - At any time (no schedule defined).

🚦 Automerge: Disabled by config. Please merge this manually once you are satisfied.

Rebasing: Whenever PR becomes conflicted, or you tick the rebase/retry checkbox.

👻 Immortal: This PR will be recreated if closed unmerged. Get config help if that's undesired.


  • If you want to rebase/retry this PR, check this box

This PR has been generated by Renovate Bot.

@elastic-renovate-prod elastic-renovate-prod bot added backport:all-open Backport to all branches that could still receive a release release_note:skip Skip the PR/issue when compiling release notes Team:DataDiscovery Discover, search (e.g. data plugin and KQL), data views, saved searches. For ES|QL, use Team:ES|QL. labels Dec 3, 2024
@elastic-renovate-prod elastic-renovate-prod bot requested a review from a team December 3, 2024 01:54
@elasticmachine
Copy link
Contributor

Pinging @elastic/kibana-data-discovery (Team:DataDiscovery)

@elastic-renovate-prod elastic-renovate-prod bot force-pushed the renovate/main-@elastickibana-data-discovery-dependencies branch from 1e135c7 to 1b04de9 Compare December 5, 2024 04:43
@davismcphee
Copy link
Contributor

/ci

@elastic-renovate-prod
Copy link
Contributor Author

Edited/Blocked Notification

Renovate will not automatically rebase this PR, because it does not recognize the last commit author and assumes somebody else may have edited the PR.

You can manually request rebase by checking the rebase/retry box above.

⚠️ Warning: custom changes will be lost.

@davismcphee davismcphee requested a review from a team as a code owner December 5, 2024 21:47
@davismcphee davismcphee requested a review from dplumlee December 5, 2024 21:47
@davismcphee
Copy link
Contributor

/ci

…ain-@elastickibana-data-discovery-dependencies
Copy link
Contributor

@nikitaindik nikitaindik left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There was a conflict, so I merged latest main to resolve.

@davismcphee, I tested the Rule Management team’s code with the upgraded packages and didn’t encounter any issues. The diff output seems to be the same for the diff configuration we use. Feel free to merge once you've fixed the tests. If there are additional changes needed for the Rule Management files, just let me know.

Wishing you a Merry Christmas! 🎄✨☺️

nikitaindik added a commit that referenced this pull request Dec 30, 2024
…205138)

**Resolves: #202016

## Summary

This PR resolves an issue where the diff view incorrectly marked certain
characters as changed (using bold font) in some cases.

## Root Cause
The issue arises from a bug in the `diff` library (v5). The library is
used to compute two-way diffs between strings (old field value and new
field value), producing an array of change objects that is then used for
rendering.

Conditions for the bug:
- `diff` v5 library is in use (fixed in v6 and above) and
`DiffMethod.WORDS` is passed as a parameter to it.
- The old field value contains a line with an addition separated by a
space (see example below).
- The next line contains some changes (additions, deletions, or
updates).


For example, for these input strings:
```
foo bar
spring
```
```
foo
sprint
```

| You would expect to see this diff | But you actually see this |
|----------|----------|
| <img width="119" alt="expected"
src="https://github.com/user-attachments/assets/c41b3dec-e578-4a12-8eb8-91fbb60d7247"
/> | <img width="118" alt="actual"
src="https://github.com/user-attachments/assets/f2a33fee-5de2-4291-876a-e7575ea07079"
/> |

**A more real-life example**
<img width="1661" alt="more_real_life"
src="https://github.com/user-attachments/assets/91ebfe93-81ad-45c8-8f9b-e173c2cf940b"
/>


## Solution
Switching to `DiffMethod.WORDS_WITH_SPACE` avoids this issue. 
Screenshot showing the difference between `DiffMethod.WORDS` and
`DiffMethod.WORDS_WITH_SPACE`:
<img width="675" alt="words_vs_words_with_space"
src="https://github.com/user-attachments/assets/3c91e1d2-63fc-4fcd-a762-a905878bfc3a"
/>

## Other changes
- Removed `DiffMethod.TRIMMED_LINES` since it's now
[deprecated](kpdecker/jsdiff#486) in the `diff`
library and we are not using it anyways.
- Stopped using the "zip" option since I believe it produces a less
readable diff, especially for cases when there's a different number of
lines in the original value vs updated value.

<details>
<summary><strong>Screenshots: with and without "zip" (click to
expand)</strong></summary>
<strong>With the "zip" option (how it was before)</strong>
<img width="1918" alt="zip"
src="https://github.com/user-attachments/assets/272ed849-47d6-4fef-8acc-ab1b22c9f42e"
/>

<strong>No "zip" (this branch)</strong>
<img width="1919" alt="no_zip"
src="https://github.com/user-attachments/assets/417303bf-9570-4ee1-98c5-8a78f59c7956"
/>
</details>

## Testing

I thoroughly tested with `DiffMethod.WORDS_WITH_SPACE` across various
inputs and scenarios, including:
- Single-line and multi-line strings.
- Numbers, arrays, and objects.
- Additions, deletions, and updates at different positions (start,
middle, and end) within and across lines.

I also validated diffs against real prebuilt rules by installing an
older Fleet package version and observed no issues.

You can test by trying different input strings and settings in
Storybook.
**Run Storybook**: `yarn storybook security_solution`.


https://github.com/user-attachments/assets/0440b73c-a4d7-40cf-9cee-e632146d292e

You can notice that `ComparisonSide` stories are broken, but that's
unrelated to these changes and needs to be handled separately.

## Compatibility with future upgrades

There's an open [PR](#202622) that
will upgrade the `diff` library from v5 to v7. I verified the behavior
of `DiffMethod.WORDS_WITH_SPACE` on v7 and found no differences compared
to v5, so it should be safe to upgrade to v7 without any changes on our
end.

Work started on 23-Dec-2024.
kibanamachine pushed a commit to kibanamachine/kibana that referenced this pull request Dec 30, 2024
…lastic#205138)

**Resolves: elastic#202016

## Summary

This PR resolves an issue where the diff view incorrectly marked certain
characters as changed (using bold font) in some cases.

## Root Cause
The issue arises from a bug in the `diff` library (v5). The library is
used to compute two-way diffs between strings (old field value and new
field value), producing an array of change objects that is then used for
rendering.

Conditions for the bug:
- `diff` v5 library is in use (fixed in v6 and above) and
`DiffMethod.WORDS` is passed as a parameter to it.
- The old field value contains a line with an addition separated by a
space (see example below).
- The next line contains some changes (additions, deletions, or
updates).

For example, for these input strings:
```
foo bar
spring
```
```
foo
sprint
```

| You would expect to see this diff | But you actually see this |
|----------|----------|
| <img width="119" alt="expected"
src="https://github.com/user-attachments/assets/c41b3dec-e578-4a12-8eb8-91fbb60d7247"
/> | <img width="118" alt="actual"
src="https://github.com/user-attachments/assets/f2a33fee-5de2-4291-876a-e7575ea07079"
/> |

**A more real-life example**
<img width="1661" alt="more_real_life"
src="https://github.com/user-attachments/assets/91ebfe93-81ad-45c8-8f9b-e173c2cf940b"
/>

## Solution
Switching to `DiffMethod.WORDS_WITH_SPACE` avoids this issue.
Screenshot showing the difference between `DiffMethod.WORDS` and
`DiffMethod.WORDS_WITH_SPACE`:
<img width="675" alt="words_vs_words_with_space"
src="https://github.com/user-attachments/assets/3c91e1d2-63fc-4fcd-a762-a905878bfc3a"
/>

## Other changes
- Removed `DiffMethod.TRIMMED_LINES` since it's now
[deprecated](kpdecker/jsdiff#486) in the `diff`
library and we are not using it anyways.
- Stopped using the "zip" option since I believe it produces a less
readable diff, especially for cases when there's a different number of
lines in the original value vs updated value.

<details>
<summary><strong>Screenshots: with and without "zip" (click to
expand)</strong></summary>
<strong>With the "zip" option (how it was before)</strong>
<img width="1918" alt="zip"
src="https://github.com/user-attachments/assets/272ed849-47d6-4fef-8acc-ab1b22c9f42e"
/>

<strong>No "zip" (this branch)</strong>
<img width="1919" alt="no_zip"
src="https://github.com/user-attachments/assets/417303bf-9570-4ee1-98c5-8a78f59c7956"
/>
</details>

## Testing

I thoroughly tested with `DiffMethod.WORDS_WITH_SPACE` across various
inputs and scenarios, including:
- Single-line and multi-line strings.
- Numbers, arrays, and objects.
- Additions, deletions, and updates at different positions (start,
middle, and end) within and across lines.

I also validated diffs against real prebuilt rules by installing an
older Fleet package version and observed no issues.

You can test by trying different input strings and settings in
Storybook.
**Run Storybook**: `yarn storybook security_solution`.

https://github.com/user-attachments/assets/0440b73c-a4d7-40cf-9cee-e632146d292e

You can notice that `ComparisonSide` stories are broken, but that's
unrelated to these changes and needs to be handled separately.

## Compatibility with future upgrades

There's an open [PR](elastic#202622) that
will upgrade the `diff` library from v5 to v7. I verified the behavior
of `DiffMethod.WORDS_WITH_SPACE` on v7 and found no differences compared
to v5, so it should be safe to upgrade to v7 without any changes on our
end.

Work started on 23-Dec-2024.

(cherry picked from commit 140c2e0)
kibanamachine added a commit that referenced this pull request Dec 30, 2024
…view (#205138) (#205253)

# Backport

This will backport the following commits from `main` to `8.x`:
- [[Security Solution] Fix incorrect changes highlighting in diff view
(#205138)](#205138)

<!--- Backport version: 9.4.3 -->

### Questions ?
Please refer to the [Backport tool
documentation](https://github.com/sqren/backport)

<!--BACKPORT [{"author":{"name":"Nikita
Indik","email":"nikita.indik@elastic.co"},"sourceCommit":{"committedDate":"2024-12-30T12:38:42Z","message":"[Security
Solution] Fix incorrect changes highlighting in diff view
(#205138)\n\n**Resolves:
https://github.com/elastic/kibana/issues/202016**\n\n## Summary\n\nThis
PR resolves an issue where the diff view incorrectly marked
certain\ncharacters as changed (using bold font) in some cases.\n\n##
Root Cause\nThe issue arises from a bug in the `diff` library (v5). The
library is\nused to compute two-way diffs between strings (old field
value and new\nfield value), producing an array of change objects that
is then used for\nrendering.\n\nConditions for the bug:\n- `diff` v5
library is in use (fixed in v6 and above) and\n`DiffMethod.WORDS` is
passed as a parameter to it.\n- The old field value contains a line with
an addition separated by a\nspace (see example below).\n- The next line
contains some changes (additions, deletions, or\nupdates).\n\n\nFor
example, for these input strings:\n```\nfoo
bar\nspring\n```\n```\nfoo\nsprint\n```\n\n| You would expect to see
this diff | But you actually see this |\n|----------|----------|\n| <img
width=\"119\"
alt=\"expected\"\nsrc=\"https://github.com/user-attachments/assets/c41b3dec-e578-4a12-8eb8-91fbb60d7247\"\n/>
| <img width=\"118\"
alt=\"actual\"\nsrc=\"https://github.com/user-attachments/assets/f2a33fee-5de2-4291-876a-e7575ea07079\"\n/>
|\n\n**A more real-life example**\n<img width=\"1661\"
alt=\"more_real_life\"\nsrc=\"https://github.com/user-attachments/assets/91ebfe93-81ad-45c8-8f9b-e173c2cf940b\"\n/>\n\n\n##
Solution\nSwitching to `DiffMethod.WORDS_WITH_SPACE` avoids this issue.
\nScreenshot showing the difference between `DiffMethod.WORDS`
and\n`DiffMethod.WORDS_WITH_SPACE`:\n<img width=\"675\"
alt=\"words_vs_words_with_space\"\nsrc=\"https://github.com/user-attachments/assets/3c91e1d2-63fc-4fcd-a762-a905878bfc3a\"\n/>\n\n##
Other changes\n- Removed `DiffMethod.TRIMMED_LINES` since it's
now\n[deprecated](kpdecker/jsdiff#486) in the
`diff`\nlibrary and we are not using it anyways.\n- Stopped using the
\"zip\" option since I believe it produces a less\nreadable diff,
especially for cases when there's a different number of\nlines in the
original value vs updated
value.\n\n<details>\n<summary><strong>Screenshots: with and without
\"zip\" (click to\nexpand)</strong></summary>\n<strong>With the \"zip\"
option (how it was before)</strong>\n<img width=\"1918\"
alt=\"zip\"\nsrc=\"https://github.com/user-attachments/assets/272ed849-47d6-4fef-8acc-ab1b22c9f42e\"\n/>\n\n<strong>No
\"zip\" (this branch)</strong>\n<img width=\"1919\"
alt=\"no_zip\"\nsrc=\"https://github.com/user-attachments/assets/417303bf-9570-4ee1-98c5-8a78f59c7956\"\n/>\n</details>\n\n##
Testing\n\nI thoroughly tested with `DiffMethod.WORDS_WITH_SPACE` across
various\ninputs and scenarios, including:\n- Single-line and multi-line
strings.\n- Numbers, arrays, and objects.\n- Additions, deletions, and
updates at different positions (start,\nmiddle, and end) within and
across lines.\n\nI also validated diffs against real prebuilt rules by
installing an\nolder Fleet package version and observed no
issues.\n\nYou can test by trying different input strings and settings
in\nStorybook.\n**Run Storybook**: `yarn storybook
security_solution`.\n\n\nhttps://github.com/user-attachments/assets/0440b73c-a4d7-40cf-9cee-e632146d292e\n\nYou
can notice that `ComparisonSide` stories are broken, but
that's\nunrelated to these changes and needs to be handled
separately.\n\n## Compatibility with future upgrades\n\nThere's an open
[PR](#202622) that\nwill upgrade
the `diff` library from v5 to v7. I verified the behavior\nof
`DiffMethod.WORDS_WITH_SPACE` on v7 and found no differences
compared\nto v5, so it should be safe to upgrade to v7 without any
changes on our\nend.\n\nWork started on
23-Dec-2024.","sha":"140c2e0ecf9f8a0277699052f9ba472066a0e96d","branchLabelMapping":{"^v9.0.0$":"main","^v8.18.0$":"8.x","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["release_note:skip","v9.0.0","Team:Detections
and Resp","Team: SecuritySolution","Feature:Rule
Management","Team:Detection Rule Management","Feature:Prebuilt Detection
Rules","backport:version","v8.18.0"],"title":"[Security Solution] Fix
incorrect changes highlighting in diff
view","number":205138,"url":"https://github.com/elastic/kibana/pull/205138","mergeCommit":{"message":"[Security
Solution] Fix incorrect changes highlighting in diff view
(#205138)\n\n**Resolves:
https://github.com/elastic/kibana/issues/202016**\n\n## Summary\n\nThis
PR resolves an issue where the diff view incorrectly marked
certain\ncharacters as changed (using bold font) in some cases.\n\n##
Root Cause\nThe issue arises from a bug in the `diff` library (v5). The
library is\nused to compute two-way diffs between strings (old field
value and new\nfield value), producing an array of change objects that
is then used for\nrendering.\n\nConditions for the bug:\n- `diff` v5
library is in use (fixed in v6 and above) and\n`DiffMethod.WORDS` is
passed as a parameter to it.\n- The old field value contains a line with
an addition separated by a\nspace (see example below).\n- The next line
contains some changes (additions, deletions, or\nupdates).\n\n\nFor
example, for these input strings:\n```\nfoo
bar\nspring\n```\n```\nfoo\nsprint\n```\n\n| You would expect to see
this diff | But you actually see this |\n|----------|----------|\n| <img
width=\"119\"
alt=\"expected\"\nsrc=\"https://github.com/user-attachments/assets/c41b3dec-e578-4a12-8eb8-91fbb60d7247\"\n/>
| <img width=\"118\"
alt=\"actual\"\nsrc=\"https://github.com/user-attachments/assets/f2a33fee-5de2-4291-876a-e7575ea07079\"\n/>
|\n\n**A more real-life example**\n<img width=\"1661\"
alt=\"more_real_life\"\nsrc=\"https://github.com/user-attachments/assets/91ebfe93-81ad-45c8-8f9b-e173c2cf940b\"\n/>\n\n\n##
Solution\nSwitching to `DiffMethod.WORDS_WITH_SPACE` avoids this issue.
\nScreenshot showing the difference between `DiffMethod.WORDS`
and\n`DiffMethod.WORDS_WITH_SPACE`:\n<img width=\"675\"
alt=\"words_vs_words_with_space\"\nsrc=\"https://github.com/user-attachments/assets/3c91e1d2-63fc-4fcd-a762-a905878bfc3a\"\n/>\n\n##
Other changes\n- Removed `DiffMethod.TRIMMED_LINES` since it's
now\n[deprecated](kpdecker/jsdiff#486) in the
`diff`\nlibrary and we are not using it anyways.\n- Stopped using the
\"zip\" option since I believe it produces a less\nreadable diff,
especially for cases when there's a different number of\nlines in the
original value vs updated
value.\n\n<details>\n<summary><strong>Screenshots: with and without
\"zip\" (click to\nexpand)</strong></summary>\n<strong>With the \"zip\"
option (how it was before)</strong>\n<img width=\"1918\"
alt=\"zip\"\nsrc=\"https://github.com/user-attachments/assets/272ed849-47d6-4fef-8acc-ab1b22c9f42e\"\n/>\n\n<strong>No
\"zip\" (this branch)</strong>\n<img width=\"1919\"
alt=\"no_zip\"\nsrc=\"https://github.com/user-attachments/assets/417303bf-9570-4ee1-98c5-8a78f59c7956\"\n/>\n</details>\n\n##
Testing\n\nI thoroughly tested with `DiffMethod.WORDS_WITH_SPACE` across
various\ninputs and scenarios, including:\n- Single-line and multi-line
strings.\n- Numbers, arrays, and objects.\n- Additions, deletions, and
updates at different positions (start,\nmiddle, and end) within and
across lines.\n\nI also validated diffs against real prebuilt rules by
installing an\nolder Fleet package version and observed no
issues.\n\nYou can test by trying different input strings and settings
in\nStorybook.\n**Run Storybook**: `yarn storybook
security_solution`.\n\n\nhttps://github.com/user-attachments/assets/0440b73c-a4d7-40cf-9cee-e632146d292e\n\nYou
can notice that `ComparisonSide` stories are broken, but
that's\nunrelated to these changes and needs to be handled
separately.\n\n## Compatibility with future upgrades\n\nThere's an open
[PR](#202622) that\nwill upgrade
the `diff` library from v5 to v7. I verified the behavior\nof
`DiffMethod.WORDS_WITH_SPACE` on v7 and found no differences
compared\nto v5, so it should be safe to upgrade to v7 without any
changes on our\nend.\n\nWork started on
23-Dec-2024.","sha":"140c2e0ecf9f8a0277699052f9ba472066a0e96d"}},"sourceBranch":"main","suggestedTargetBranches":["8.x"],"targetPullRequestStates":[{"branch":"main","label":"v9.0.0","branchLabelMappingKey":"^v9.0.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/205138","number":205138,"mergeCommit":{"message":"[Security
Solution] Fix incorrect changes highlighting in diff view
(#205138)\n\n**Resolves:
https://github.com/elastic/kibana/issues/202016**\n\n## Summary\n\nThis
PR resolves an issue where the diff view incorrectly marked
certain\ncharacters as changed (using bold font) in some cases.\n\n##
Root Cause\nThe issue arises from a bug in the `diff` library (v5). The
library is\nused to compute two-way diffs between strings (old field
value and new\nfield value), producing an array of change objects that
is then used for\nrendering.\n\nConditions for the bug:\n- `diff` v5
library is in use (fixed in v6 and above) and\n`DiffMethod.WORDS` is
passed as a parameter to it.\n- The old field value contains a line with
an addition separated by a\nspace (see example below).\n- The next line
contains some changes (additions, deletions, or\nupdates).\n\n\nFor
example, for these input strings:\n```\nfoo
bar\nspring\n```\n```\nfoo\nsprint\n```\n\n| You would expect to see
this diff | But you actually see this |\n|----------|----------|\n| <img
width=\"119\"
alt=\"expected\"\nsrc=\"https://github.com/user-attachments/assets/c41b3dec-e578-4a12-8eb8-91fbb60d7247\"\n/>
| <img width=\"118\"
alt=\"actual\"\nsrc=\"https://github.com/user-attachments/assets/f2a33fee-5de2-4291-876a-e7575ea07079\"\n/>
|\n\n**A more real-life example**\n<img width=\"1661\"
alt=\"more_real_life\"\nsrc=\"https://github.com/user-attachments/assets/91ebfe93-81ad-45c8-8f9b-e173c2cf940b\"\n/>\n\n\n##
Solution\nSwitching to `DiffMethod.WORDS_WITH_SPACE` avoids this issue.
\nScreenshot showing the difference between `DiffMethod.WORDS`
and\n`DiffMethod.WORDS_WITH_SPACE`:\n<img width=\"675\"
alt=\"words_vs_words_with_space\"\nsrc=\"https://github.com/user-attachments/assets/3c91e1d2-63fc-4fcd-a762-a905878bfc3a\"\n/>\n\n##
Other changes\n- Removed `DiffMethod.TRIMMED_LINES` since it's
now\n[deprecated](kpdecker/jsdiff#486) in the
`diff`\nlibrary and we are not using it anyways.\n- Stopped using the
\"zip\" option since I believe it produces a less\nreadable diff,
especially for cases when there's a different number of\nlines in the
original value vs updated
value.\n\n<details>\n<summary><strong>Screenshots: with and without
\"zip\" (click to\nexpand)</strong></summary>\n<strong>With the \"zip\"
option (how it was before)</strong>\n<img width=\"1918\"
alt=\"zip\"\nsrc=\"https://github.com/user-attachments/assets/272ed849-47d6-4fef-8acc-ab1b22c9f42e\"\n/>\n\n<strong>No
\"zip\" (this branch)</strong>\n<img width=\"1919\"
alt=\"no_zip\"\nsrc=\"https://github.com/user-attachments/assets/417303bf-9570-4ee1-98c5-8a78f59c7956\"\n/>\n</details>\n\n##
Testing\n\nI thoroughly tested with `DiffMethod.WORDS_WITH_SPACE` across
various\ninputs and scenarios, including:\n- Single-line and multi-line
strings.\n- Numbers, arrays, and objects.\n- Additions, deletions, and
updates at different positions (start,\nmiddle, and end) within and
across lines.\n\nI also validated diffs against real prebuilt rules by
installing an\nolder Fleet package version and observed no
issues.\n\nYou can test by trying different input strings and settings
in\nStorybook.\n**Run Storybook**: `yarn storybook
security_solution`.\n\n\nhttps://github.com/user-attachments/assets/0440b73c-a4d7-40cf-9cee-e632146d292e\n\nYou
can notice that `ComparisonSide` stories are broken, but
that's\nunrelated to these changes and needs to be handled
separately.\n\n## Compatibility with future upgrades\n\nThere's an open
[PR](#202622) that\nwill upgrade
the `diff` library from v5 to v7. I verified the behavior\nof
`DiffMethod.WORDS_WITH_SPACE` on v7 and found no differences
compared\nto v5, so it should be safe to upgrade to v7 without any
changes on our\nend.\n\nWork started on
23-Dec-2024.","sha":"140c2e0ecf9f8a0277699052f9ba472066a0e96d"}},{"branch":"8.x","label":"v8.18.0","branchLabelMappingKey":"^v8.18.0$","isSourceBranch":false,"state":"NOT_CREATED"}]}]
BACKPORT-->

Co-authored-by: Nikita Indik <nikita.indik@elastic.co>
stratoula pushed a commit to stratoula/kibana that referenced this pull request Jan 2, 2025
…lastic#205138)

**Resolves: elastic#202016

## Summary

This PR resolves an issue where the diff view incorrectly marked certain
characters as changed (using bold font) in some cases.

## Root Cause
The issue arises from a bug in the `diff` library (v5). The library is
used to compute two-way diffs between strings (old field value and new
field value), producing an array of change objects that is then used for
rendering.

Conditions for the bug:
- `diff` v5 library is in use (fixed in v6 and above) and
`DiffMethod.WORDS` is passed as a parameter to it.
- The old field value contains a line with an addition separated by a
space (see example below).
- The next line contains some changes (additions, deletions, or
updates).


For example, for these input strings:
```
foo bar
spring
```
```
foo
sprint
```

| You would expect to see this diff | But you actually see this |
|----------|----------|
| <img width="119" alt="expected"
src="https://github.com/user-attachments/assets/c41b3dec-e578-4a12-8eb8-91fbb60d7247"
/> | <img width="118" alt="actual"
src="https://github.com/user-attachments/assets/f2a33fee-5de2-4291-876a-e7575ea07079"
/> |

**A more real-life example**
<img width="1661" alt="more_real_life"
src="https://github.com/user-attachments/assets/91ebfe93-81ad-45c8-8f9b-e173c2cf940b"
/>


## Solution
Switching to `DiffMethod.WORDS_WITH_SPACE` avoids this issue. 
Screenshot showing the difference between `DiffMethod.WORDS` and
`DiffMethod.WORDS_WITH_SPACE`:
<img width="675" alt="words_vs_words_with_space"
src="https://github.com/user-attachments/assets/3c91e1d2-63fc-4fcd-a762-a905878bfc3a"
/>

## Other changes
- Removed `DiffMethod.TRIMMED_LINES` since it's now
[deprecated](kpdecker/jsdiff#486) in the `diff`
library and we are not using it anyways.
- Stopped using the "zip" option since I believe it produces a less
readable diff, especially for cases when there's a different number of
lines in the original value vs updated value.

<details>
<summary><strong>Screenshots: with and without "zip" (click to
expand)</strong></summary>
<strong>With the "zip" option (how it was before)</strong>
<img width="1918" alt="zip"
src="https://github.com/user-attachments/assets/272ed849-47d6-4fef-8acc-ab1b22c9f42e"
/>

<strong>No "zip" (this branch)</strong>
<img width="1919" alt="no_zip"
src="https://github.com/user-attachments/assets/417303bf-9570-4ee1-98c5-8a78f59c7956"
/>
</details>

## Testing

I thoroughly tested with `DiffMethod.WORDS_WITH_SPACE` across various
inputs and scenarios, including:
- Single-line and multi-line strings.
- Numbers, arrays, and objects.
- Additions, deletions, and updates at different positions (start,
middle, and end) within and across lines.

I also validated diffs against real prebuilt rules by installing an
older Fleet package version and observed no issues.

You can test by trying different input strings and settings in
Storybook.
**Run Storybook**: `yarn storybook security_solution`.


https://github.com/user-attachments/assets/0440b73c-a4d7-40cf-9cee-e632146d292e

You can notice that `ComparisonSide` stories are broken, but that's
unrelated to these changes and needs to be handled separately.

## Compatibility with future upgrades

There's an open [PR](elastic#202622) that
will upgrade the `diff` library from v5 to v7. I verified the behavior
of `DiffMethod.WORDS_WITH_SPACE` on v7 and found no differences compared
to v5, so it should be safe to upgrade to v7 without any changes on our
end.

Work started on 23-Dec-2024.
benakansara pushed a commit to benakansara/kibana that referenced this pull request Jan 2, 2025
…lastic#205138)

**Resolves: elastic#202016

## Summary

This PR resolves an issue where the diff view incorrectly marked certain
characters as changed (using bold font) in some cases.

## Root Cause
The issue arises from a bug in the `diff` library (v5). The library is
used to compute two-way diffs between strings (old field value and new
field value), producing an array of change objects that is then used for
rendering.

Conditions for the bug:
- `diff` v5 library is in use (fixed in v6 and above) and
`DiffMethod.WORDS` is passed as a parameter to it.
- The old field value contains a line with an addition separated by a
space (see example below).
- The next line contains some changes (additions, deletions, or
updates).


For example, for these input strings:
```
foo bar
spring
```
```
foo
sprint
```

| You would expect to see this diff | But you actually see this |
|----------|----------|
| <img width="119" alt="expected"
src="https://github.com/user-attachments/assets/c41b3dec-e578-4a12-8eb8-91fbb60d7247"
/> | <img width="118" alt="actual"
src="https://github.com/user-attachments/assets/f2a33fee-5de2-4291-876a-e7575ea07079"
/> |

**A more real-life example**
<img width="1661" alt="more_real_life"
src="https://github.com/user-attachments/assets/91ebfe93-81ad-45c8-8f9b-e173c2cf940b"
/>


## Solution
Switching to `DiffMethod.WORDS_WITH_SPACE` avoids this issue. 
Screenshot showing the difference between `DiffMethod.WORDS` and
`DiffMethod.WORDS_WITH_SPACE`:
<img width="675" alt="words_vs_words_with_space"
src="https://github.com/user-attachments/assets/3c91e1d2-63fc-4fcd-a762-a905878bfc3a"
/>

## Other changes
- Removed `DiffMethod.TRIMMED_LINES` since it's now
[deprecated](kpdecker/jsdiff#486) in the `diff`
library and we are not using it anyways.
- Stopped using the "zip" option since I believe it produces a less
readable diff, especially for cases when there's a different number of
lines in the original value vs updated value.

<details>
<summary><strong>Screenshots: with and without "zip" (click to
expand)</strong></summary>
<strong>With the "zip" option (how it was before)</strong>
<img width="1918" alt="zip"
src="https://github.com/user-attachments/assets/272ed849-47d6-4fef-8acc-ab1b22c9f42e"
/>

<strong>No "zip" (this branch)</strong>
<img width="1919" alt="no_zip"
src="https://github.com/user-attachments/assets/417303bf-9570-4ee1-98c5-8a78f59c7956"
/>
</details>

## Testing

I thoroughly tested with `DiffMethod.WORDS_WITH_SPACE` across various
inputs and scenarios, including:
- Single-line and multi-line strings.
- Numbers, arrays, and objects.
- Additions, deletions, and updates at different positions (start,
middle, and end) within and across lines.

I also validated diffs against real prebuilt rules by installing an
older Fleet package version and observed no issues.

You can test by trying different input strings and settings in
Storybook.
**Run Storybook**: `yarn storybook security_solution`.


https://github.com/user-attachments/assets/0440b73c-a4d7-40cf-9cee-e632146d292e

You can notice that `ComparisonSide` stories are broken, but that's
unrelated to these changes and needs to be handled separately.

## Compatibility with future upgrades

There's an open [PR](elastic#202622) that
will upgrade the `diff` library from v5 to v7. I verified the behavior
of `DiffMethod.WORDS_WITH_SPACE` on v7 and found no differences compared
to v5, so it should be safe to upgrade to v7 without any changes on our
end.

Work started on 23-Dec-2024.
cqliu1 pushed a commit to cqliu1/kibana that referenced this pull request Jan 2, 2025
…lastic#205138)

**Resolves: elastic#202016

## Summary

This PR resolves an issue where the diff view incorrectly marked certain
characters as changed (using bold font) in some cases.

## Root Cause
The issue arises from a bug in the `diff` library (v5). The library is
used to compute two-way diffs between strings (old field value and new
field value), producing an array of change objects that is then used for
rendering.

Conditions for the bug:
- `diff` v5 library is in use (fixed in v6 and above) and
`DiffMethod.WORDS` is passed as a parameter to it.
- The old field value contains a line with an addition separated by a
space (see example below).
- The next line contains some changes (additions, deletions, or
updates).


For example, for these input strings:
```
foo bar
spring
```
```
foo
sprint
```

| You would expect to see this diff | But you actually see this |
|----------|----------|
| <img width="119" alt="expected"
src="https://github.com/user-attachments/assets/c41b3dec-e578-4a12-8eb8-91fbb60d7247"
/> | <img width="118" alt="actual"
src="https://github.com/user-attachments/assets/f2a33fee-5de2-4291-876a-e7575ea07079"
/> |

**A more real-life example**
<img width="1661" alt="more_real_life"
src="https://github.com/user-attachments/assets/91ebfe93-81ad-45c8-8f9b-e173c2cf940b"
/>


## Solution
Switching to `DiffMethod.WORDS_WITH_SPACE` avoids this issue. 
Screenshot showing the difference between `DiffMethod.WORDS` and
`DiffMethod.WORDS_WITH_SPACE`:
<img width="675" alt="words_vs_words_with_space"
src="https://github.com/user-attachments/assets/3c91e1d2-63fc-4fcd-a762-a905878bfc3a"
/>

## Other changes
- Removed `DiffMethod.TRIMMED_LINES` since it's now
[deprecated](kpdecker/jsdiff#486) in the `diff`
library and we are not using it anyways.
- Stopped using the "zip" option since I believe it produces a less
readable diff, especially for cases when there's a different number of
lines in the original value vs updated value.

<details>
<summary><strong>Screenshots: with and without "zip" (click to
expand)</strong></summary>
<strong>With the "zip" option (how it was before)</strong>
<img width="1918" alt="zip"
src="https://github.com/user-attachments/assets/272ed849-47d6-4fef-8acc-ab1b22c9f42e"
/>

<strong>No "zip" (this branch)</strong>
<img width="1919" alt="no_zip"
src="https://github.com/user-attachments/assets/417303bf-9570-4ee1-98c5-8a78f59c7956"
/>
</details>

## Testing

I thoroughly tested with `DiffMethod.WORDS_WITH_SPACE` across various
inputs and scenarios, including:
- Single-line and multi-line strings.
- Numbers, arrays, and objects.
- Additions, deletions, and updates at different positions (start,
middle, and end) within and across lines.

I also validated diffs against real prebuilt rules by installing an
older Fleet package version and observed no issues.

You can test by trying different input strings and settings in
Storybook.
**Run Storybook**: `yarn storybook security_solution`.


https://github.com/user-attachments/assets/0440b73c-a4d7-40cf-9cee-e632146d292e

You can notice that `ComparisonSide` stories are broken, but that's
unrelated to these changes and needs to be handled separately.

## Compatibility with future upgrades

There's an open [PR](elastic#202622) that
will upgrade the `diff` library from v5 to v7. I verified the behavior
of `DiffMethod.WORDS_WITH_SPACE` on v7 and found no differences compared
to v5, so it should be safe to upgrade to v7 without any changes on our
end.

Work started on 23-Dec-2024.
@davismcphee
Copy link
Contributor

/ci

@davismcphee davismcphee requested a review from a team as a code owner January 3, 2025 23:38
@davismcphee
Copy link
Contributor

/ci

@davismcphee davismcphee self-assigned this Jan 4, 2025
@davismcphee
Copy link
Contributor

@elastic/kibana-data-discovery I think this should be good for review on our end now. I tested locally and as far as I can tell there's no negative impact from updating these dependencies, but it would be good to get someone else's eyes on it too just in case 🙏

Copy link
Contributor

@jughosta jughosta left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure about backport:all-open. Can we limit it to 9.x?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Example of how the output is different now:

  • before:
Screenshot 2025-01-06 at 15 00 13
  • after:
Screenshot 2025-01-06 at 15 00 28

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As briefly discussed in our sync, the change in output here is likely due to kpdecker/jsdiff#439 where diff deletions are now prioritized over additions, which is apparently the standard behaviour for the Myers diff algorithm (v5 implemented in incorrectly). While technically breaking, I think the change is minor enough (and more consistent with other diff tools) that we can safely backport to 8.x, although I'll only target prev-minor instead of all-open to be careful.

nikitaindik added a commit to nikitaindik/kibana that referenced this pull request Jan 6, 2025
…lastic#205138)

**Resolves: elastic#202016

## Summary

This PR resolves an issue where the diff view incorrectly marked certain
characters as changed (using bold font) in some cases.

## Root Cause
The issue arises from a bug in the `diff` library (v5). The library is
used to compute two-way diffs between strings (old field value and new
field value), producing an array of change objects that is then used for
rendering.

Conditions for the bug:
- `diff` v5 library is in use (fixed in v6 and above) and
`DiffMethod.WORDS` is passed as a parameter to it.
- The old field value contains a line with an addition separated by a
space (see example below).
- The next line contains some changes (additions, deletions, or
updates).

For example, for these input strings:
```
foo bar
spring
```
```
foo
sprint
```

| You would expect to see this diff | But you actually see this |
|----------|----------|
| <img width="119" alt="expected"
src="https://github.com/user-attachments/assets/c41b3dec-e578-4a12-8eb8-91fbb60d7247"
/> | <img width="118" alt="actual"
src="https://github.com/user-attachments/assets/f2a33fee-5de2-4291-876a-e7575ea07079"
/> |

**A more real-life example**
<img width="1661" alt="more_real_life"
src="https://github.com/user-attachments/assets/91ebfe93-81ad-45c8-8f9b-e173c2cf940b"
/>

## Solution
Switching to `DiffMethod.WORDS_WITH_SPACE` avoids this issue.
Screenshot showing the difference between `DiffMethod.WORDS` and
`DiffMethod.WORDS_WITH_SPACE`:
<img width="675" alt="words_vs_words_with_space"
src="https://github.com/user-attachments/assets/3c91e1d2-63fc-4fcd-a762-a905878bfc3a"
/>

## Other changes
- Removed `DiffMethod.TRIMMED_LINES` since it's now
[deprecated](kpdecker/jsdiff#486) in the `diff`
library and we are not using it anyways.
- Stopped using the "zip" option since I believe it produces a less
readable diff, especially for cases when there's a different number of
lines in the original value vs updated value.

<details>
<summary><strong>Screenshots: with and without "zip" (click to
expand)</strong></summary>
<strong>With the "zip" option (how it was before)</strong>
<img width="1918" alt="zip"
src="https://github.com/user-attachments/assets/272ed849-47d6-4fef-8acc-ab1b22c9f42e"
/>

<strong>No "zip" (this branch)</strong>
<img width="1919" alt="no_zip"
src="https://github.com/user-attachments/assets/417303bf-9570-4ee1-98c5-8a78f59c7956"
/>
</details>

## Testing

I thoroughly tested with `DiffMethod.WORDS_WITH_SPACE` across various
inputs and scenarios, including:
- Single-line and multi-line strings.
- Numbers, arrays, and objects.
- Additions, deletions, and updates at different positions (start,
middle, and end) within and across lines.

I also validated diffs against real prebuilt rules by installing an
older Fleet package version and observed no issues.

You can test by trying different input strings and settings in
Storybook.
**Run Storybook**: `yarn storybook security_solution`.

https://github.com/user-attachments/assets/0440b73c-a4d7-40cf-9cee-e632146d292e

You can notice that `ComparisonSide` stories are broken, but that's
unrelated to these changes and needs to be handled separately.

## Compatibility with future upgrades

There's an open [PR](elastic#202622) that
will upgrade the `diff` library from v5 to v7. I verified the behavior
of `DiffMethod.WORDS_WITH_SPACE` on v7 and found no differences compared
to v5, so it should be safe to upgrade to v7 without any changes on our
end.

Work started on 23-Dec-2024.

(cherry picked from commit 140c2e0)

# Conflicts:
#	x-pack/plugins/security_solution/public/detection_engine/rule_management/components/rule_details/json_diff/diff_view.stories.tsx
nikitaindik added a commit to nikitaindik/kibana that referenced this pull request Jan 6, 2025
…lastic#205138)

**Resolves: elastic#202016

## Summary

This PR resolves an issue where the diff view incorrectly marked certain
characters as changed (using bold font) in some cases.

## Root Cause
The issue arises from a bug in the `diff` library (v5). The library is
used to compute two-way diffs between strings (old field value and new
field value), producing an array of change objects that is then used for
rendering.

Conditions for the bug:
- `diff` v5 library is in use (fixed in v6 and above) and
`DiffMethod.WORDS` is passed as a parameter to it.
- The old field value contains a line with an addition separated by a
space (see example below).
- The next line contains some changes (additions, deletions, or
updates).

For example, for these input strings:
```
foo bar
spring
```
```
foo
sprint
```

| You would expect to see this diff | But you actually see this |
|----------|----------|
| <img width="119" alt="expected"
src="https://github.com/user-attachments/assets/c41b3dec-e578-4a12-8eb8-91fbb60d7247"
/> | <img width="118" alt="actual"
src="https://github.com/user-attachments/assets/f2a33fee-5de2-4291-876a-e7575ea07079"
/> |

**A more real-life example**
<img width="1661" alt="more_real_life"
src="https://github.com/user-attachments/assets/91ebfe93-81ad-45c8-8f9b-e173c2cf940b"
/>

## Solution
Switching to `DiffMethod.WORDS_WITH_SPACE` avoids this issue.
Screenshot showing the difference between `DiffMethod.WORDS` and
`DiffMethod.WORDS_WITH_SPACE`:
<img width="675" alt="words_vs_words_with_space"
src="https://github.com/user-attachments/assets/3c91e1d2-63fc-4fcd-a762-a905878bfc3a"
/>

## Other changes
- Removed `DiffMethod.TRIMMED_LINES` since it's now
[deprecated](kpdecker/jsdiff#486) in the `diff`
library and we are not using it anyways.
- Stopped using the "zip" option since I believe it produces a less
readable diff, especially for cases when there's a different number of
lines in the original value vs updated value.

<details>
<summary><strong>Screenshots: with and without "zip" (click to
expand)</strong></summary>
<strong>With the "zip" option (how it was before)</strong>
<img width="1918" alt="zip"
src="https://github.com/user-attachments/assets/272ed849-47d6-4fef-8acc-ab1b22c9f42e"
/>

<strong>No "zip" (this branch)</strong>
<img width="1919" alt="no_zip"
src="https://github.com/user-attachments/assets/417303bf-9570-4ee1-98c5-8a78f59c7956"
/>
</details>

## Testing

I thoroughly tested with `DiffMethod.WORDS_WITH_SPACE` across various
inputs and scenarios, including:
- Single-line and multi-line strings.
- Numbers, arrays, and objects.
- Additions, deletions, and updates at different positions (start,
middle, and end) within and across lines.

I also validated diffs against real prebuilt rules by installing an
older Fleet package version and observed no issues.

You can test by trying different input strings and settings in
Storybook.
**Run Storybook**: `yarn storybook security_solution`.

https://github.com/user-attachments/assets/0440b73c-a4d7-40cf-9cee-e632146d292e

You can notice that `ComparisonSide` stories are broken, but that's
unrelated to these changes and needs to be handled separately.

## Compatibility with future upgrades

There's an open [PR](elastic#202622) that
will upgrade the `diff` library from v5 to v7. I verified the behavior
of `DiffMethod.WORDS_WITH_SPACE` on v7 and found no differences compared
to v5, so it should be safe to upgrade to v7 without any changes on our
end.

Work started on 23-Dec-2024.

(cherry picked from commit 140c2e0)

# Conflicts:
#	x-pack/plugins/security_solution/public/detection_engine/rule_management/components/rule_details/json_diff/diff_view.stories.tsx
@davismcphee
Copy link
Contributor

/ci

nikitaindik added a commit that referenced this pull request Jan 6, 2025
… view (#205138) (#205612)

# Backport

This will backport the following commits from `main` to `8.16`:
- [[Security Solution] Fix incorrect changes highlighting in diff view
(#205138)](#205138)

<!--- Backport version: 8.9.8 -->

### Questions ?
Please refer to the [Backport tool
documentation](https://github.com/sqren/backport)

<!--BACKPORT [{"author":{"name":"Nikita
Indik","email":"nikita.indik@elastic.co"},"sourceCommit":{"committedDate":"2024-12-30T12:38:42Z","message":"[Security
Solution] Fix incorrect changes highlighting in diff view
(#205138)\n\n**Resolves:
https://github.com/elastic/kibana/issues/202016**\n\n## Summary\n\nThis
PR resolves an issue where the diff view incorrectly marked
certain\ncharacters as changed (using bold font) in some cases.\n\n##
Root Cause\nThe issue arises from a bug in the `diff` library (v5). The
library is\nused to compute two-way diffs between strings (old field
value and new\nfield value), producing an array of change objects that
is then used for\nrendering.\n\nConditions for the bug:\n- `diff` v5
library is in use (fixed in v6 and above) and\n`DiffMethod.WORDS` is
passed as a parameter to it.\n- The old field value contains a line with
an addition separated by a\nspace (see example below).\n- The next line
contains some changes (additions, deletions, or\nupdates).\n\n\nFor
example, for these input strings:\n```\nfoo
bar\nspring\n```\n```\nfoo\nsprint\n```\n\n| You would expect to see
this diff | But you actually see this |\n|----------|----------|\n| <img
width=\"119\"
alt=\"expected\"\nsrc=\"https://github.com/user-attachments/assets/c41b3dec-e578-4a12-8eb8-91fbb60d7247\"\n/>
| <img width=\"118\"
alt=\"actual\"\nsrc=\"https://github.com/user-attachments/assets/f2a33fee-5de2-4291-876a-e7575ea07079\"\n/>
|\n\n**A more real-life example**\n<img width=\"1661\"
alt=\"more_real_life\"\nsrc=\"https://github.com/user-attachments/assets/91ebfe93-81ad-45c8-8f9b-e173c2cf940b\"\n/>\n\n\n##
Solution\nSwitching to `DiffMethod.WORDS_WITH_SPACE` avoids this issue.
\nScreenshot showing the difference between `DiffMethod.WORDS`
and\n`DiffMethod.WORDS_WITH_SPACE`:\n<img width=\"675\"
alt=\"words_vs_words_with_space\"\nsrc=\"https://github.com/user-attachments/assets/3c91e1d2-63fc-4fcd-a762-a905878bfc3a\"\n/>\n\n##
Other changes\n- Removed `DiffMethod.TRIMMED_LINES` since it's
now\n[deprecated](kpdecker/jsdiff#486) in the
`diff`\nlibrary and we are not using it anyways.\n- Stopped using the
\"zip\" option since I believe it produces a less\nreadable diff,
especially for cases when there's a different number of\nlines in the
original value vs updated
value.\n\n<details>\n<summary><strong>Screenshots: with and without
\"zip\" (click to\nexpand)</strong></summary>\n<strong>With the \"zip\"
option (how it was before)</strong>\n<img width=\"1918\"
alt=\"zip\"\nsrc=\"https://github.com/user-attachments/assets/272ed849-47d6-4fef-8acc-ab1b22c9f42e\"\n/>\n\n<strong>No
\"zip\" (this branch)</strong>\n<img width=\"1919\"
alt=\"no_zip\"\nsrc=\"https://github.com/user-attachments/assets/417303bf-9570-4ee1-98c5-8a78f59c7956\"\n/>\n</details>\n\n##
Testing\n\nI thoroughly tested with `DiffMethod.WORDS_WITH_SPACE` across
various\ninputs and scenarios, including:\n- Single-line and multi-line
strings.\n- Numbers, arrays, and objects.\n- Additions, deletions, and
updates at different positions (start,\nmiddle, and end) within and
across lines.\n\nI also validated diffs against real prebuilt rules by
installing an\nolder Fleet package version and observed no
issues.\n\nYou can test by trying different input strings and settings
in\nStorybook.\n**Run Storybook**: `yarn storybook
security_solution`.\n\n\nhttps://github.com/user-attachments/assets/0440b73c-a4d7-40cf-9cee-e632146d292e\n\nYou
can notice that `ComparisonSide` stories are broken, but
that's\nunrelated to these changes and needs to be handled
separately.\n\n## Compatibility with future upgrades\n\nThere's an open
[PR](#202622) that\nwill upgrade
the `diff` library from v5 to v7. I verified the behavior\nof
`DiffMethod.WORDS_WITH_SPACE` on v7 and found no differences
compared\nto v5, so it should be safe to upgrade to v7 without any
changes on our\nend.\n\nWork started on
23-Dec-2024.","sha":"140c2e0ecf9f8a0277699052f9ba472066a0e96d","branchLabelMapping":{"^v9.0.0$":"main","^v8.18.0$":"8.x","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["release_note:skip","v9.0.0","Team:Detections
and Resp","Team: SecuritySolution","Feature:Rule
Management","Team:Detection Rule Management","Feature:Prebuilt Detection
Rules","backport:version","v8.18.0"],"number":205138,"url":"https://github.com/elastic/kibana/pull/205138","mergeCommit":{"message":"[Security
Solution] Fix incorrect changes highlighting in diff view
(#205138)\n\n**Resolves:
https://github.com/elastic/kibana/issues/202016**\n\n## Summary\n\nThis
PR resolves an issue where the diff view incorrectly marked
certain\ncharacters as changed (using bold font) in some cases.\n\n##
Root Cause\nThe issue arises from a bug in the `diff` library (v5). The
library is\nused to compute two-way diffs between strings (old field
value and new\nfield value), producing an array of change objects that
is then used for\nrendering.\n\nConditions for the bug:\n- `diff` v5
library is in use (fixed in v6 and above) and\n`DiffMethod.WORDS` is
passed as a parameter to it.\n- The old field value contains a line with
an addition separated by a\nspace (see example below).\n- The next line
contains some changes (additions, deletions, or\nupdates).\n\n\nFor
example, for these input strings:\n```\nfoo
bar\nspring\n```\n```\nfoo\nsprint\n```\n\n| You would expect to see
this diff | But you actually see this |\n|----------|----------|\n| <img
width=\"119\"
alt=\"expected\"\nsrc=\"https://github.com/user-attachments/assets/c41b3dec-e578-4a12-8eb8-91fbb60d7247\"\n/>
| <img width=\"118\"
alt=\"actual\"\nsrc=\"https://github.com/user-attachments/assets/f2a33fee-5de2-4291-876a-e7575ea07079\"\n/>
|\n\n**A more real-life example**\n<img width=\"1661\"
alt=\"more_real_life\"\nsrc=\"https://github.com/user-attachments/assets/91ebfe93-81ad-45c8-8f9b-e173c2cf940b\"\n/>\n\n\n##
Solution\nSwitching to `DiffMethod.WORDS_WITH_SPACE` avoids this issue.
\nScreenshot showing the difference between `DiffMethod.WORDS`
and\n`DiffMethod.WORDS_WITH_SPACE`:\n<img width=\"675\"
alt=\"words_vs_words_with_space\"\nsrc=\"https://github.com/user-attachments/assets/3c91e1d2-63fc-4fcd-a762-a905878bfc3a\"\n/>\n\n##
Other changes\n- Removed `DiffMethod.TRIMMED_LINES` since it's
now\n[deprecated](kpdecker/jsdiff#486) in the
`diff`\nlibrary and we are not using it anyways.\n- Stopped using the
\"zip\" option since I believe it produces a less\nreadable diff,
especially for cases when there's a different number of\nlines in the
original value vs updated
value.\n\n<details>\n<summary><strong>Screenshots: with and without
\"zip\" (click to\nexpand)</strong></summary>\n<strong>With the \"zip\"
option (how it was before)</strong>\n<img width=\"1918\"
alt=\"zip\"\nsrc=\"https://github.com/user-attachments/assets/272ed849-47d6-4fef-8acc-ab1b22c9f42e\"\n/>\n\n<strong>No
\"zip\" (this branch)</strong>\n<img width=\"1919\"
alt=\"no_zip\"\nsrc=\"https://github.com/user-attachments/assets/417303bf-9570-4ee1-98c5-8a78f59c7956\"\n/>\n</details>\n\n##
Testing\n\nI thoroughly tested with `DiffMethod.WORDS_WITH_SPACE` across
various\ninputs and scenarios, including:\n- Single-line and multi-line
strings.\n- Numbers, arrays, and objects.\n- Additions, deletions, and
updates at different positions (start,\nmiddle, and end) within and
across lines.\n\nI also validated diffs against real prebuilt rules by
installing an\nolder Fleet package version and observed no
issues.\n\nYou can test by trying different input strings and settings
in\nStorybook.\n**Run Storybook**: `yarn storybook
security_solution`.\n\n\nhttps://github.com/user-attachments/assets/0440b73c-a4d7-40cf-9cee-e632146d292e\n\nYou
can notice that `ComparisonSide` stories are broken, but
that's\nunrelated to these changes and needs to be handled
separately.\n\n## Compatibility with future upgrades\n\nThere's an open
[PR](#202622) that\nwill upgrade
the `diff` library from v5 to v7. I verified the behavior\nof
`DiffMethod.WORDS_WITH_SPACE` on v7 and found no differences
compared\nto v5, so it should be safe to upgrade to v7 without any
changes on our\nend.\n\nWork started on
23-Dec-2024.","sha":"140c2e0ecf9f8a0277699052f9ba472066a0e96d"}},"sourceBranch":"main","suggestedTargetBranches":[],"targetPullRequestStates":[{"branch":"main","label":"v9.0.0","labelRegex":"^v9.0.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/205138","number":205138,"mergeCommit":{"message":"[Security
Solution] Fix incorrect changes highlighting in diff view
(#205138)\n\n**Resolves:
https://github.com/elastic/kibana/issues/202016**\n\n## Summary\n\nThis
PR resolves an issue where the diff view incorrectly marked
certain\ncharacters as changed (using bold font) in some cases.\n\n##
Root Cause\nThe issue arises from a bug in the `diff` library (v5). The
library is\nused to compute two-way diffs between strings (old field
value and new\nfield value), producing an array of change objects that
is then used for\nrendering.\n\nConditions for the bug:\n- `diff` v5
library is in use (fixed in v6 and above) and\n`DiffMethod.WORDS` is
passed as a parameter to it.\n- The old field value contains a line with
an addition separated by a\nspace (see example below).\n- The next line
contains some changes (additions, deletions, or\nupdates).\n\n\nFor
example, for these input strings:\n```\nfoo
bar\nspring\n```\n```\nfoo\nsprint\n```\n\n| You would expect to see
this diff | But you actually see this |\n|----------|----------|\n| <img
width=\"119\"
alt=\"expected\"\nsrc=\"https://github.com/user-attachments/assets/c41b3dec-e578-4a12-8eb8-91fbb60d7247\"\n/>
| <img width=\"118\"
alt=\"actual\"\nsrc=\"https://github.com/user-attachments/assets/f2a33fee-5de2-4291-876a-e7575ea07079\"\n/>
|\n\n**A more real-life example**\n<img width=\"1661\"
alt=\"more_real_life\"\nsrc=\"https://github.com/user-attachments/assets/91ebfe93-81ad-45c8-8f9b-e173c2cf940b\"\n/>\n\n\n##
Solution\nSwitching to `DiffMethod.WORDS_WITH_SPACE` avoids this issue.
\nScreenshot showing the difference between `DiffMethod.WORDS`
and\n`DiffMethod.WORDS_WITH_SPACE`:\n<img width=\"675\"
alt=\"words_vs_words_with_space\"\nsrc=\"https://github.com/user-attachments/assets/3c91e1d2-63fc-4fcd-a762-a905878bfc3a\"\n/>\n\n##
Other changes\n- Removed `DiffMethod.TRIMMED_LINES` since it's
now\n[deprecated](kpdecker/jsdiff#486) in the
`diff`\nlibrary and we are not using it anyways.\n- Stopped using the
\"zip\" option since I believe it produces a less\nreadable diff,
especially for cases when there's a different number of\nlines in the
original value vs updated
value.\n\n<details>\n<summary><strong>Screenshots: with and without
\"zip\" (click to\nexpand)</strong></summary>\n<strong>With the \"zip\"
option (how it was before)</strong>\n<img width=\"1918\"
alt=\"zip\"\nsrc=\"https://github.com/user-attachments/assets/272ed849-47d6-4fef-8acc-ab1b22c9f42e\"\n/>\n\n<strong>No
\"zip\" (this branch)</strong>\n<img width=\"1919\"
alt=\"no_zip\"\nsrc=\"https://github.com/user-attachments/assets/417303bf-9570-4ee1-98c5-8a78f59c7956\"\n/>\n</details>\n\n##
Testing\n\nI thoroughly tested with `DiffMethod.WORDS_WITH_SPACE` across
various\ninputs and scenarios, including:\n- Single-line and multi-line
strings.\n- Numbers, arrays, and objects.\n- Additions, deletions, and
updates at different positions (start,\nmiddle, and end) within and
across lines.\n\nI also validated diffs against real prebuilt rules by
installing an\nolder Fleet package version and observed no
issues.\n\nYou can test by trying different input strings and settings
in\nStorybook.\n**Run Storybook**: `yarn storybook
security_solution`.\n\n\nhttps://github.com/user-attachments/assets/0440b73c-a4d7-40cf-9cee-e632146d292e\n\nYou
can notice that `ComparisonSide` stories are broken, but
that's\nunrelated to these changes and needs to be handled
separately.\n\n## Compatibility with future upgrades\n\nThere's an open
[PR](#202622) that\nwill upgrade
the `diff` library from v5 to v7. I verified the behavior\nof
`DiffMethod.WORDS_WITH_SPACE` on v7 and found no differences
compared\nto v5, so it should be safe to upgrade to v7 without any
changes on our\nend.\n\nWork started on
23-Dec-2024.","sha":"140c2e0ecf9f8a0277699052f9ba472066a0e96d"}},{"branch":"8.x","label":"v8.18.0","labelRegex":"^v8.18.0$","isSourceBranch":false,"url":"https://github.com/elastic/kibana/pull/205253","number":205253,"state":"MERGED","mergeCommit":{"sha":"2c736a7fcb9e8e8f209f1734562992b39fa2ebe7","message":"[8.x]
[Security Solution] Fix incorrect changes highlighting in diff view
(#205138) (#205253)\n\n# Backport\n\nThis will backport the following
commits from `main` to `8.x`:\n- [[Security Solution] Fix incorrect
changes highlighting in diff
view\n(#205138)](https://github.com/elastic/kibana/pull/205138)\n\n<!---
Backport version: 9.4.3 -->\n\n### Questions ?\nPlease refer to the
[Backport
tool\ndocumentation](https://github.com/sqren/backport)\n\n<!--BACKPORT
[{\"author\":{\"name\":\"Nikita\nIndik\",\"email\":\"nikita.indik@elastic.co\"},\"sourceCommit\":{\"committedDate\":\"2024-12-30T12:38:42Z\",\"message\":\"[Security\nSolution]
Fix incorrect changes highlighting in diff
view\n(#205138)\\n\\n**Resolves:\nhttps://github.com//issues/202016**\\n\\n##
Summary\\n\\nThis\nPR resolves an issue where the diff view incorrectly
marked\ncertain\\ncharacters as changed (using bold font) in some
cases.\\n\\n##\nRoot Cause\\nThe issue arises from a bug in the `diff`
library (v5). The\nlibrary is\\nused to compute two-way diffs between
strings (old field\nvalue and new\\nfield value), producing an array of
change objects that\nis then used for\\nrendering.\\n\\nConditions for
the bug:\\n- `diff` v5\nlibrary is in use (fixed in v6 and above)
and\\n`DiffMethod.WORDS` is\npassed as a parameter to it.\\n- The old
field value contains a line with\nan addition separated by a\\nspace
(see example below).\\n- The next line\ncontains some changes
(additions, deletions, or\\nupdates).\\n\\n\\nFor\nexample, for these
input
strings:\\n```\\nfoo\nbar\\nspring\\n```\\n```\\nfoo\\nsprint\\n```\\n\\n|
You would expect to see\nthis diff | But you actually see this
|\\n|----------|----------|\\n|
<img\nwidth=\\\"119\\\"\nalt=\\\"expected\\\"\\nsrc=\\\"https://github.com/user-attachments/assets/c41b3dec-e578-4a12-8eb8-91fbb60d7247\\\"\\n/>\n|
<img
width=\\\"118\\\"\nalt=\\\"actual\\\"\\nsrc=\\\"https://github.com/user-attachments/assets/f2a33fee-5de2-4291-876a-e7575ea07079\\\"\\n/>\n|\\n\\n**A
more real-life example**\\n<img
width=\\\"1661\\\"\nalt=\\\"more_real_life\\\"\\nsrc=\\\"https://github.com/user-attachments/assets/91ebfe93-81ad-45c8-8f9b-e173c2cf940b\\\"\\n/>\\n\\n\\n##\nSolution\\nSwitching
to `DiffMethod.WORDS_WITH_SPACE` avoids this issue.\n\\nScreenshot
showing the difference between
`DiffMethod.WORDS`\nand\\n`DiffMethod.WORDS_WITH_SPACE`:\\n<img
width=\\\"675\\\"\nalt=\\\"words_vs_words_with_space\\\"\\nsrc=\\\"https://github.com/user-attachments/assets/3c91e1d2-63fc-4fcd-a762-a905878bfc3a\\\"\\n/>\\n\\n##\nOther
changes\\n- Removed `DiffMethod.TRIMMED_LINES` since
it's\nnow\\n[deprecated](kpdecker/jsdiff#486) in
the\n`diff`\\nlibrary and we are not using it anyways.\\n- Stopped using
the\n\\\"zip\\\" option since I believe it produces a less\\nreadable
diff,\nespecially for cases when there's a different number of\\nlines
in the\noriginal value vs
updated\nvalue.\\n\\n<details>\\n<summary><strong>Screenshots: with and
without\n\\\"zip\\\" (click
to\\nexpand)</strong></summary>\\n<strong>With the \\\"zip\\\"\noption
(how it was before)</strong>\\n<img
width=\\\"1918\\\"\nalt=\\\"zip\\\"\\nsrc=\\\"https://github.com/user-attachments/assets/272ed849-47d6-4fef-8acc-ab1b22c9f42e\\\"\\n/>\\n\\n<strong>No\n\\\"zip\\\"
(this branch)</strong>\\n<img
width=\\\"1919\\\"\nalt=\\\"no_zip\\\"\\nsrc=\\\"https://github.com/user-attachments/assets/417303bf-9570-4ee1-98c5-8a78f59c7956\\\"\\n/>\\n</details>\\n\\n##\nTesting\\n\\nI
thoroughly tested with `DiffMethod.WORDS_WITH_SPACE`
across\nvarious\\ninputs and scenarios, including:\\n- Single-line and
multi-line\nstrings.\\n- Numbers, arrays, and objects.\\n- Additions,
deletions, and\nupdates at different positions (start,\\nmiddle, and
end) within and\nacross lines.\\n\\nI also validated diffs against real
prebuilt rules by\ninstalling an\\nolder Fleet package version and
observed no\nissues.\\n\\nYou can test by trying different input strings
and settings\nin\\nStorybook.\\n**Run Storybook**: `yarn
storybook\nsecurity_solution`.\\n\\n\\nhttps://github.com/user-attachments/assets/0440b73c-a4d7-40cf-9cee-e632146d292e\\n\\nYou\ncan
notice that `ComparisonSide` stories are broken, but\nthat's\\nunrelated
to these changes and needs to be handled\nseparately.\\n\\n##
Compatibility with future upgrades\\n\\nThere's an
open\n[PR](#202622) that\\nwill
upgrade\nthe `diff` library from v5 to v7. I verified the
behavior\\nof\n`DiffMethod.WORDS_WITH_SPACE` on v7 and found no
differences\ncompared\\nto v5, so it should be safe to upgrade to v7
without any\nchanges on our\\nend.\\n\\nWork started
on\n23-Dec-2024.\",\"sha\":\"140c2e0ecf9f8a0277699052f9ba472066a0e96d\",\"branchLabelMapping\":{\"^v9.0.0$\":\"main\",\"^v8.18.0$\":\"8.x\",\"^v(\\\\d+).(\\\\d+).\\\\d+$\":\"$1.$2\"}},\"sourcePullRequest\":{\"labels\":[\"release_note:skip\",\"v9.0.0\",\"Team:Detections\nand
Resp\",\"Team:
SecuritySolution\",\"Feature:Rule\nManagement\",\"Team:Detection Rule
Management\",\"Feature:Prebuilt
Detection\nRules\",\"backport:version\",\"v8.18.0\"],\"title\":\"[Security
Solution] Fix\nincorrect changes highlighting in
diff\nview\",\"number\":205138,\"url\":\"https://github.com/elastic/kibana/pull/205138\",\"mergeCommit\":{\"message\":\"[Security\nSolution]
Fix incorrect changes highlighting in diff
view\n(#205138)\\n\\n**Resolves:\nhttps://github.com//issues/202016**\\n\\n##
Summary\\n\\nThis\nPR resolves an issue where the diff view incorrectly
marked\ncertain\\ncharacters as changed (using bold font) in some
cases.\\n\\n##\nRoot Cause\\nThe issue arises from a bug in the `diff`
library (v5). The\nlibrary is\\nused to compute two-way diffs between
strings (old field\nvalue and new\\nfield value), producing an array of
change objects that\nis then used for\\nrendering.\\n\\nConditions for
the bug:\\n- `diff` v5\nlibrary is in use (fixed in v6 and above)
and\\n`DiffMethod.WORDS` is\npassed as a parameter to it.\\n- The old
field value contains a line with\nan addition separated by a\\nspace
(see example below).\\n- The next line\ncontains some changes
(additions, deletions, or\\nupdates).\\n\\n\\nFor\nexample, for these
input
strings:\\n```\\nfoo\nbar\\nspring\\n```\\n```\\nfoo\\nsprint\\n```\\n\\n|
You would expect to see\nthis diff | But you actually see this
|\\n|----------|----------|\\n|
<img\nwidth=\\\"119\\\"\nalt=\\\"expected\\\"\\nsrc=\\\"https://github.com/user-attachments/assets/c41b3dec-e578-4a12-8eb8-91fbb60d7247\\\"\\n/>\n|
<img
width=\\\"118\\\"\nalt=\\\"actual\\\"\\nsrc=\\\"https://github.com/user-attachments/assets/f2a33fee-5de2-4291-876a-e7575ea07079\\\"\\n/>\n|\\n\\n**A
more real-life example**\\n<img
width=\\\"1661\\\"\nalt=\\\"more_real_life\\\"\\nsrc=\\\"https://github.com/user-attachments/assets/91ebfe93-81ad-45c8-8f9b-e173c2cf940b\\\"\\n/>\\n\\n\\n##\nSolution\\nSwitching
to `DiffMethod.WORDS_WITH_SPACE` avoids this issue.\n\\nScreenshot
showing the difference between
`DiffMethod.WORDS`\nand\\n`DiffMethod.WORDS_WITH_SPACE`:\\n<img
width=\\\"675\\\"\nalt=\\\"words_vs_words_with_space\\\"\\nsrc=\\\"https://github.com/user-attachments/assets/3c91e1d2-63fc-4fcd-a762-a905878bfc3a\\\"\\n/>\\n\\n##\nOther
changes\\n- Removed `DiffMethod.TRIMMED_LINES` since
it's\nnow\\n[deprecated](kpdecker/jsdiff#486) in
the\n`diff`\\nlibrary and we are not using it anyways.\\n- Stopped using
the\n\\\"zip\\\" option since I believe it produces a less\\nreadable
diff,\nespecially for cases when there's a different number of\\nlines
in the\noriginal value vs
updated\nvalue.\\n\\n<details>\\n<summary><strong>Screenshots: with and
without\n\\\"zip\\\" (click
to\\nexpand)</strong></summary>\\n<strong>With the \\\"zip\\\"\noption
(how it was before)</strong>\\n<img
width=\\\"1918\\\"\nalt=\\\"zip\\\"\\nsrc=\\\"https://github.com/user-attachments/assets/272ed849-47d6-4fef-8acc-ab1b22c9f42e\\\"\\n/>\\n\\n<strong>No\n\\\"zip\\\"
(this branch)</strong>\\n<img
width=\\\"1919\\\"\nalt=\\\"no_zip\\\"\\nsrc=\\\"https://github.com/user-attachments/assets/417303bf-9570-4ee1-98c5-8a78f59c7956\\\"\\n/>\\n</details>\\n\\n##\nTesting\\n\\nI
thoroughly tested with `DiffMethod.WORDS_WITH_SPACE`
across\nvarious\\ninputs and scenarios, including:\\n- Single-line and
multi-line\nstrings.\\n- Numbers, arrays, and objects.\\n- Additions,
deletions, and\nupdates at different positions (start,\\nmiddle, and
end) within and\nacross lines.\\n\\nI also validated diffs against real
prebuilt rules by\ninstalling an\\nolder Fleet package version and
observed no\nissues.\\n\\nYou can test by trying different input strings
and settings\nin\\nStorybook.\\n**Run Storybook**: `yarn
storybook\nsecurity_solution`.\\n\\n\\nhttps://github.com/user-attachments/assets/0440b73c-a4d7-40cf-9cee-e632146d292e\\n\\nYou\ncan
notice that `ComparisonSide` stories are broken, but\nthat's\\nunrelated
to these changes and needs to be handled\nseparately.\\n\\n##
Compatibility with future upgrades\\n\\nThere's an
open\n[PR](#202622) that\\nwill
upgrade\nthe `diff` library from v5 to v7. I verified the
behavior\\nof\n`DiffMethod.WORDS_WITH_SPACE` on v7 and found no
differences\ncompared\\nto v5, so it should be safe to upgrade to v7
without any\nchanges on our\\nend.\\n\\nWork started
on\n23-Dec-2024.\",\"sha\":\"140c2e0ecf9f8a0277699052f9ba472066a0e96d\"}},\"sourceBranch\":\"main\",\"suggestedTargetBranches\":[\"8.x\"],\"targetPullRequestStates\":[{\"branch\":\"main\",\"label\":\"v9.0.0\",\"branchLabelMappingKey\":\"^v9.0.0$\",\"isSourceBranch\":true,\"state\":\"MERGED\",\"url\":\"https://github.com/elastic/kibana/pull/205138\",\"number\":205138,\"mergeCommit\":{\"message\":\"[Security\nSolution]
Fix incorrect changes highlighting in diff
view\n(#205138)\\n\\n**Resolves:\nhttps://github.com//issues/202016**\\n\\n##
Summary\\n\\nThis\nPR resolves an issue where the diff view incorrectly
marked\ncertain\\ncharacters as changed (using bold font) in some
cases.\\n\\n##\nRoot Cause\\nThe issue arises from a bug in the `diff`
library (v5). The\nlibrary is\\nused to compute two-way diffs between
strings (old field\nvalue and new\\nfield value), producing an array of
change objects that\nis then used for\\nrendering.\\n\\nConditions for
the bug:\\n- `diff` v5\nlibrary is in use (fixed in v6 and above)
and\\n`DiffMethod.WORDS` is\npassed as a parameter to it.\\n- The old
field value contains a line with\nan addition separated by a\\nspace
(see example below).\\n- The next line\ncontains some changes
(additions, deletions, or\\nupdates).\\n\\n\\nFor\nexample, for these
input
strings:\\n```\\nfoo\nbar\\nspring\\n```\\n```\\nfoo\\nsprint\\n```\\n\\n|
You would expect to see\nthis diff | But you actually see this
|\\n|----------|----------|\\n|
<img\nwidth=\\\"119\\\"\nalt=\\\"expected\\\"\\nsrc=\\\"https://github.com/user-attachments/assets/c41b3dec-e578-4a12-8eb8-91fbb60d7247\\\"\\n/>\n|
<img
width=\\\"118\\\"\nalt=\\\"actual\\\"\\nsrc=\\\"https://github.com/user-attachments/assets/f2a33fee-5de2-4291-876a-e7575ea07079\\\"\\n/>\n|\\n\\n**A
more real-life example**\\n<img
width=\\\"1661\\\"\nalt=\\\"more_real_life\\\"\\nsrc=\\\"https://github.com/user-attachments/assets/91ebfe93-81ad-45c8-8f9b-e173c2cf940b\\\"\\n/>\\n\\n\\n##\nSolution\\nSwitching
to `DiffMethod.WORDS_WITH_SPACE` avoids this issue.\n\\nScreenshot
showing the difference between
`DiffMethod.WORDS`\nand\\n`DiffMethod.WORDS_WITH_SPACE`:\\n<img
width=\\\"675\\\"\nalt=\\\"words_vs_words_with_space\\\"\\nsrc=\\\"https://github.com/user-attachments/assets/3c91e1d2-63fc-4fcd-a762-a905878bfc3a\\\"\\n/>\\n\\n##\nOther
changes\\n- Removed `DiffMethod.TRIMMED_LINES` since
it's\nnow\\n[deprecated](kpdecker/jsdiff#486) in
the\n`diff`\\nlibrary and we are not using it anyways.\\n- Stopped using
the\n\\\"zip\\\" option since I believe it produces a less\\nreadable
diff,\nespecially for cases when there's a different number of\\nlines
in the\noriginal value vs
updated\nvalue.\\n\\n<details>\\n<summary><strong>Screenshots: with and
without\n\\\"zip\\\" (click
to\\nexpand)</strong></summary>\\n<strong>With the \\\"zip\\\"\noption
(how it was before)</strong>\\n<img
width=\\\"1918\\\"\nalt=\\\"zip\\\"\\nsrc=\\\"https://github.com/user-attachments/assets/272ed849-47d6-4fef-8acc-ab1b22c9f42e\\\"\\n/>\\n\\n<strong>No\n\\\"zip\\\"
(this branch)</strong>\\n<img
width=\\\"1919\\\"\nalt=\\\"no_zip\\\"\\nsrc=\\\"https://github.com/user-attachments/assets/417303bf-9570-4ee1-98c5-8a78f59c7956\\\"\\n/>\\n</details>\\n\\n##\nTesting\\n\\nI
thoroughly tested with `DiffMethod.WORDS_WITH_SPACE`
across\nvarious\\ninputs and scenarios, including:\\n- Single-line and
multi-line\nstrings.\\n- Numbers, arrays, and objects.\\n- Additions,
deletions, and\nupdates at different positions (start,\\nmiddle, and
end) within and\nacross lines.\\n\\nI also validated diffs against real
prebuilt rules by\ninstalling an\\nolder Fleet package version and
observed no\nissues.\\n\\nYou can test by trying different input strings
and settings\nin\\nStorybook.\\n**Run Storybook**: `yarn
storybook\nsecurity_solution`.\\n\\n\\nhttps://github.com/user-attachments/assets/0440b73c-a4d7-40cf-9cee-e632146d292e\\n\\nYou\ncan
notice that `ComparisonSide` stories are broken, but\nthat's\\nunrelated
to these changes and needs to be handled\nseparately.\\n\\n##
Compatibility with future upgrades\\n\\nThere's an
open\n[PR](#202622) that\\nwill
upgrade\nthe `diff` library from v5 to v7. I verified the
behavior\\nof\n`DiffMethod.WORDS_WITH_SPACE` on v7 and found no
differences\ncompared\\nto v5, so it should be safe to upgrade to v7
without any\nchanges on our\\nend.\\n\\nWork started
on\n23-Dec-2024.\",\"sha\":\"140c2e0ecf9f8a0277699052f9ba472066a0e96d\"}},{\"branch\":\"8.x\",\"label\":\"v8.18.0\",\"branchLabelMappingKey\":\"^v8.18.0$\",\"isSourceBranch\":false,\"state\":\"NOT_CREATED\"}]}]\nBACKPORT-->\n\nCo-authored-by:
Nikita Indik <nikita.indik@elastic.co>"}}]}] BACKPORT-->
nikitaindik added a commit that referenced this pull request Jan 6, 2025
… view (#205138) (#205611)

# Backport

This will backport the following commits from `main` to `8.17`:
- [[Security Solution] Fix incorrect changes highlighting in diff view
(#205138)](#205138)

<!--- Backport version: 8.9.8 -->

### Questions ?
Please refer to the [Backport tool
documentation](https://github.com/sqren/backport)

<!--BACKPORT [{"author":{"name":"Nikita
Indik","email":"nikita.indik@elastic.co"},"sourceCommit":{"committedDate":"2024-12-30T12:38:42Z","message":"[Security
Solution] Fix incorrect changes highlighting in diff view
(#205138)\n\n**Resolves:
https://github.com/elastic/kibana/issues/202016**\n\n## Summary\n\nThis
PR resolves an issue where the diff view incorrectly marked
certain\ncharacters as changed (using bold font) in some cases.\n\n##
Root Cause\nThe issue arises from a bug in the `diff` library (v5). The
library is\nused to compute two-way diffs between strings (old field
value and new\nfield value), producing an array of change objects that
is then used for\nrendering.\n\nConditions for the bug:\n- `diff` v5
library is in use (fixed in v6 and above) and\n`DiffMethod.WORDS` is
passed as a parameter to it.\n- The old field value contains a line with
an addition separated by a\nspace (see example below).\n- The next line
contains some changes (additions, deletions, or\nupdates).\n\n\nFor
example, for these input strings:\n```\nfoo
bar\nspring\n```\n```\nfoo\nsprint\n```\n\n| You would expect to see
this diff | But you actually see this |\n|----------|----------|\n| <img
width=\"119\"
alt=\"expected\"\nsrc=\"https://github.com/user-attachments/assets/c41b3dec-e578-4a12-8eb8-91fbb60d7247\"\n/>
| <img width=\"118\"
alt=\"actual\"\nsrc=\"https://github.com/user-attachments/assets/f2a33fee-5de2-4291-876a-e7575ea07079\"\n/>
|\n\n**A more real-life example**\n<img width=\"1661\"
alt=\"more_real_life\"\nsrc=\"https://github.com/user-attachments/assets/91ebfe93-81ad-45c8-8f9b-e173c2cf940b\"\n/>\n\n\n##
Solution\nSwitching to `DiffMethod.WORDS_WITH_SPACE` avoids this issue.
\nScreenshot showing the difference between `DiffMethod.WORDS`
and\n`DiffMethod.WORDS_WITH_SPACE`:\n<img width=\"675\"
alt=\"words_vs_words_with_space\"\nsrc=\"https://github.com/user-attachments/assets/3c91e1d2-63fc-4fcd-a762-a905878bfc3a\"\n/>\n\n##
Other changes\n- Removed `DiffMethod.TRIMMED_LINES` since it's
now\n[deprecated](kpdecker/jsdiff#486) in the
`diff`\nlibrary and we are not using it anyways.\n- Stopped using the
\"zip\" option since I believe it produces a less\nreadable diff,
especially for cases when there's a different number of\nlines in the
original value vs updated
value.\n\n<details>\n<summary><strong>Screenshots: with and without
\"zip\" (click to\nexpand)</strong></summary>\n<strong>With the \"zip\"
option (how it was before)</strong>\n<img width=\"1918\"
alt=\"zip\"\nsrc=\"https://github.com/user-attachments/assets/272ed849-47d6-4fef-8acc-ab1b22c9f42e\"\n/>\n\n<strong>No
\"zip\" (this branch)</strong>\n<img width=\"1919\"
alt=\"no_zip\"\nsrc=\"https://github.com/user-attachments/assets/417303bf-9570-4ee1-98c5-8a78f59c7956\"\n/>\n</details>\n\n##
Testing\n\nI thoroughly tested with `DiffMethod.WORDS_WITH_SPACE` across
various\ninputs and scenarios, including:\n- Single-line and multi-line
strings.\n- Numbers, arrays, and objects.\n- Additions, deletions, and
updates at different positions (start,\nmiddle, and end) within and
across lines.\n\nI also validated diffs against real prebuilt rules by
installing an\nolder Fleet package version and observed no
issues.\n\nYou can test by trying different input strings and settings
in\nStorybook.\n**Run Storybook**: `yarn storybook
security_solution`.\n\n\nhttps://github.com/user-attachments/assets/0440b73c-a4d7-40cf-9cee-e632146d292e\n\nYou
can notice that `ComparisonSide` stories are broken, but
that's\nunrelated to these changes and needs to be handled
separately.\n\n## Compatibility with future upgrades\n\nThere's an open
[PR](#202622) that\nwill upgrade
the `diff` library from v5 to v7. I verified the behavior\nof
`DiffMethod.WORDS_WITH_SPACE` on v7 and found no differences
compared\nto v5, so it should be safe to upgrade to v7 without any
changes on our\nend.\n\nWork started on
23-Dec-2024.","sha":"140c2e0ecf9f8a0277699052f9ba472066a0e96d","branchLabelMapping":{"^v9.0.0$":"main","^v8.18.0$":"8.x","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["release_note:skip","v9.0.0","Team:Detections
and Resp","Team: SecuritySolution","Feature:Rule
Management","Team:Detection Rule Management","Feature:Prebuilt Detection
Rules","backport:version","v8.18.0"],"number":205138,"url":"https://github.com/elastic/kibana/pull/205138","mergeCommit":{"message":"[Security
Solution] Fix incorrect changes highlighting in diff view
(#205138)\n\n**Resolves:
https://github.com/elastic/kibana/issues/202016**\n\n## Summary\n\nThis
PR resolves an issue where the diff view incorrectly marked
certain\ncharacters as changed (using bold font) in some cases.\n\n##
Root Cause\nThe issue arises from a bug in the `diff` library (v5). The
library is\nused to compute two-way diffs between strings (old field
value and new\nfield value), producing an array of change objects that
is then used for\nrendering.\n\nConditions for the bug:\n- `diff` v5
library is in use (fixed in v6 and above) and\n`DiffMethod.WORDS` is
passed as a parameter to it.\n- The old field value contains a line with
an addition separated by a\nspace (see example below).\n- The next line
contains some changes (additions, deletions, or\nupdates).\n\n\nFor
example, for these input strings:\n```\nfoo
bar\nspring\n```\n```\nfoo\nsprint\n```\n\n| You would expect to see
this diff | But you actually see this |\n|----------|----------|\n| <img
width=\"119\"
alt=\"expected\"\nsrc=\"https://github.com/user-attachments/assets/c41b3dec-e578-4a12-8eb8-91fbb60d7247\"\n/>
| <img width=\"118\"
alt=\"actual\"\nsrc=\"https://github.com/user-attachments/assets/f2a33fee-5de2-4291-876a-e7575ea07079\"\n/>
|\n\n**A more real-life example**\n<img width=\"1661\"
alt=\"more_real_life\"\nsrc=\"https://github.com/user-attachments/assets/91ebfe93-81ad-45c8-8f9b-e173c2cf940b\"\n/>\n\n\n##
Solution\nSwitching to `DiffMethod.WORDS_WITH_SPACE` avoids this issue.
\nScreenshot showing the difference between `DiffMethod.WORDS`
and\n`DiffMethod.WORDS_WITH_SPACE`:\n<img width=\"675\"
alt=\"words_vs_words_with_space\"\nsrc=\"https://github.com/user-attachments/assets/3c91e1d2-63fc-4fcd-a762-a905878bfc3a\"\n/>\n\n##
Other changes\n- Removed `DiffMethod.TRIMMED_LINES` since it's
now\n[deprecated](kpdecker/jsdiff#486) in the
`diff`\nlibrary and we are not using it anyways.\n- Stopped using the
\"zip\" option since I believe it produces a less\nreadable diff,
especially for cases when there's a different number of\nlines in the
original value vs updated
value.\n\n<details>\n<summary><strong>Screenshots: with and without
\"zip\" (click to\nexpand)</strong></summary>\n<strong>With the \"zip\"
option (how it was before)</strong>\n<img width=\"1918\"
alt=\"zip\"\nsrc=\"https://github.com/user-attachments/assets/272ed849-47d6-4fef-8acc-ab1b22c9f42e\"\n/>\n\n<strong>No
\"zip\" (this branch)</strong>\n<img width=\"1919\"
alt=\"no_zip\"\nsrc=\"https://github.com/user-attachments/assets/417303bf-9570-4ee1-98c5-8a78f59c7956\"\n/>\n</details>\n\n##
Testing\n\nI thoroughly tested with `DiffMethod.WORDS_WITH_SPACE` across
various\ninputs and scenarios, including:\n- Single-line and multi-line
strings.\n- Numbers, arrays, and objects.\n- Additions, deletions, and
updates at different positions (start,\nmiddle, and end) within and
across lines.\n\nI also validated diffs against real prebuilt rules by
installing an\nolder Fleet package version and observed no
issues.\n\nYou can test by trying different input strings and settings
in\nStorybook.\n**Run Storybook**: `yarn storybook
security_solution`.\n\n\nhttps://github.com/user-attachments/assets/0440b73c-a4d7-40cf-9cee-e632146d292e\n\nYou
can notice that `ComparisonSide` stories are broken, but
that's\nunrelated to these changes and needs to be handled
separately.\n\n## Compatibility with future upgrades\n\nThere's an open
[PR](#202622) that\nwill upgrade
the `diff` library from v5 to v7. I verified the behavior\nof
`DiffMethod.WORDS_WITH_SPACE` on v7 and found no differences
compared\nto v5, so it should be safe to upgrade to v7 without any
changes on our\nend.\n\nWork started on
23-Dec-2024.","sha":"140c2e0ecf9f8a0277699052f9ba472066a0e96d"}},"sourceBranch":"main","suggestedTargetBranches":[],"targetPullRequestStates":[{"branch":"main","label":"v9.0.0","labelRegex":"^v9.0.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/205138","number":205138,"mergeCommit":{"message":"[Security
Solution] Fix incorrect changes highlighting in diff view
(#205138)\n\n**Resolves:
https://github.com/elastic/kibana/issues/202016**\n\n## Summary\n\nThis
PR resolves an issue where the diff view incorrectly marked
certain\ncharacters as changed (using bold font) in some cases.\n\n##
Root Cause\nThe issue arises from a bug in the `diff` library (v5). The
library is\nused to compute two-way diffs between strings (old field
value and new\nfield value), producing an array of change objects that
is then used for\nrendering.\n\nConditions for the bug:\n- `diff` v5
library is in use (fixed in v6 and above) and\n`DiffMethod.WORDS` is
passed as a parameter to it.\n- The old field value contains a line with
an addition separated by a\nspace (see example below).\n- The next line
contains some changes (additions, deletions, or\nupdates).\n\n\nFor
example, for these input strings:\n```\nfoo
bar\nspring\n```\n```\nfoo\nsprint\n```\n\n| You would expect to see
this diff | But you actually see this |\n|----------|----------|\n| <img
width=\"119\"
alt=\"expected\"\nsrc=\"https://github.com/user-attachments/assets/c41b3dec-e578-4a12-8eb8-91fbb60d7247\"\n/>
| <img width=\"118\"
alt=\"actual\"\nsrc=\"https://github.com/user-attachments/assets/f2a33fee-5de2-4291-876a-e7575ea07079\"\n/>
|\n\n**A more real-life example**\n<img width=\"1661\"
alt=\"more_real_life\"\nsrc=\"https://github.com/user-attachments/assets/91ebfe93-81ad-45c8-8f9b-e173c2cf940b\"\n/>\n\n\n##
Solution\nSwitching to `DiffMethod.WORDS_WITH_SPACE` avoids this issue.
\nScreenshot showing the difference between `DiffMethod.WORDS`
and\n`DiffMethod.WORDS_WITH_SPACE`:\n<img width=\"675\"
alt=\"words_vs_words_with_space\"\nsrc=\"https://github.com/user-attachments/assets/3c91e1d2-63fc-4fcd-a762-a905878bfc3a\"\n/>\n\n##
Other changes\n- Removed `DiffMethod.TRIMMED_LINES` since it's
now\n[deprecated](kpdecker/jsdiff#486) in the
`diff`\nlibrary and we are not using it anyways.\n- Stopped using the
\"zip\" option since I believe it produces a less\nreadable diff,
especially for cases when there's a different number of\nlines in the
original value vs updated
value.\n\n<details>\n<summary><strong>Screenshots: with and without
\"zip\" (click to\nexpand)</strong></summary>\n<strong>With the \"zip\"
option (how it was before)</strong>\n<img width=\"1918\"
alt=\"zip\"\nsrc=\"https://github.com/user-attachments/assets/272ed849-47d6-4fef-8acc-ab1b22c9f42e\"\n/>\n\n<strong>No
\"zip\" (this branch)</strong>\n<img width=\"1919\"
alt=\"no_zip\"\nsrc=\"https://github.com/user-attachments/assets/417303bf-9570-4ee1-98c5-8a78f59c7956\"\n/>\n</details>\n\n##
Testing\n\nI thoroughly tested with `DiffMethod.WORDS_WITH_SPACE` across
various\ninputs and scenarios, including:\n- Single-line and multi-line
strings.\n- Numbers, arrays, and objects.\n- Additions, deletions, and
updates at different positions (start,\nmiddle, and end) within and
across lines.\n\nI also validated diffs against real prebuilt rules by
installing an\nolder Fleet package version and observed no
issues.\n\nYou can test by trying different input strings and settings
in\nStorybook.\n**Run Storybook**: `yarn storybook
security_solution`.\n\n\nhttps://github.com/user-attachments/assets/0440b73c-a4d7-40cf-9cee-e632146d292e\n\nYou
can notice that `ComparisonSide` stories are broken, but
that's\nunrelated to these changes and needs to be handled
separately.\n\n## Compatibility with future upgrades\n\nThere's an open
[PR](#202622) that\nwill upgrade
the `diff` library from v5 to v7. I verified the behavior\nof
`DiffMethod.WORDS_WITH_SPACE` on v7 and found no differences
compared\nto v5, so it should be safe to upgrade to v7 without any
changes on our\nend.\n\nWork started on
23-Dec-2024.","sha":"140c2e0ecf9f8a0277699052f9ba472066a0e96d"}},{"branch":"8.x","label":"v8.18.0","labelRegex":"^v8.18.0$","isSourceBranch":false,"url":"https://github.com/elastic/kibana/pull/205253","number":205253,"state":"MERGED","mergeCommit":{"sha":"2c736a7fcb9e8e8f209f1734562992b39fa2ebe7","message":"[8.x]
[Security Solution] Fix incorrect changes highlighting in diff view
(#205138) (#205253)\n\n# Backport\n\nThis will backport the following
commits from `main` to `8.x`:\n- [[Security Solution] Fix incorrect
changes highlighting in diff
view\n(#205138)](https://github.com/elastic/kibana/pull/205138)\n\n<!---
Backport version: 9.4.3 -->\n\n### Questions ?\nPlease refer to the
[Backport
tool\ndocumentation](https://github.com/sqren/backport)\n\n<!--BACKPORT
[{\"author\":{\"name\":\"Nikita\nIndik\",\"email\":\"nikita.indik@elastic.co\"},\"sourceCommit\":{\"committedDate\":\"2024-12-30T12:38:42Z\",\"message\":\"[Security\nSolution]
Fix incorrect changes highlighting in diff
view\n(#205138)\\n\\n**Resolves:\nhttps://github.com//issues/202016**\\n\\n##
Summary\\n\\nThis\nPR resolves an issue where the diff view incorrectly
marked\ncertain\\ncharacters as changed (using bold font) in some
cases.\\n\\n##\nRoot Cause\\nThe issue arises from a bug in the `diff`
library (v5). The\nlibrary is\\nused to compute two-way diffs between
strings (old field\nvalue and new\\nfield value), producing an array of
change objects that\nis then used for\\nrendering.\\n\\nConditions for
the bug:\\n- `diff` v5\nlibrary is in use (fixed in v6 and above)
and\\n`DiffMethod.WORDS` is\npassed as a parameter to it.\\n- The old
field value contains a line with\nan addition separated by a\\nspace
(see example below).\\n- The next line\ncontains some changes
(additions, deletions, or\\nupdates).\\n\\n\\nFor\nexample, for these
input
strings:\\n```\\nfoo\nbar\\nspring\\n```\\n```\\nfoo\\nsprint\\n```\\n\\n|
You would expect to see\nthis diff | But you actually see this
|\\n|----------|----------|\\n|
<img\nwidth=\\\"119\\\"\nalt=\\\"expected\\\"\\nsrc=\\\"https://github.com/user-attachments/assets/c41b3dec-e578-4a12-8eb8-91fbb60d7247\\\"\\n/>\n|
<img
width=\\\"118\\\"\nalt=\\\"actual\\\"\\nsrc=\\\"https://github.com/user-attachments/assets/f2a33fee-5de2-4291-876a-e7575ea07079\\\"\\n/>\n|\\n\\n**A
more real-life example**\\n<img
width=\\\"1661\\\"\nalt=\\\"more_real_life\\\"\\nsrc=\\\"https://github.com/user-attachments/assets/91ebfe93-81ad-45c8-8f9b-e173c2cf940b\\\"\\n/>\\n\\n\\n##\nSolution\\nSwitching
to `DiffMethod.WORDS_WITH_SPACE` avoids this issue.\n\\nScreenshot
showing the difference between
`DiffMethod.WORDS`\nand\\n`DiffMethod.WORDS_WITH_SPACE`:\\n<img
width=\\\"675\\\"\nalt=\\\"words_vs_words_with_space\\\"\\nsrc=\\\"https://github.com/user-attachments/assets/3c91e1d2-63fc-4fcd-a762-a905878bfc3a\\\"\\n/>\\n\\n##\nOther
changes\\n- Removed `DiffMethod.TRIMMED_LINES` since
it's\nnow\\n[deprecated](kpdecker/jsdiff#486) in
the\n`diff`\\nlibrary and we are not using it anyways.\\n- Stopped using
the\n\\\"zip\\\" option since I believe it produces a less\\nreadable
diff,\nespecially for cases when there's a different number of\\nlines
in the\noriginal value vs
updated\nvalue.\\n\\n<details>\\n<summary><strong>Screenshots: with and
without\n\\\"zip\\\" (click
to\\nexpand)</strong></summary>\\n<strong>With the \\\"zip\\\"\noption
(how it was before)</strong>\\n<img
width=\\\"1918\\\"\nalt=\\\"zip\\\"\\nsrc=\\\"https://github.com/user-attachments/assets/272ed849-47d6-4fef-8acc-ab1b22c9f42e\\\"\\n/>\\n\\n<strong>No\n\\\"zip\\\"
(this branch)</strong>\\n<img
width=\\\"1919\\\"\nalt=\\\"no_zip\\\"\\nsrc=\\\"https://github.com/user-attachments/assets/417303bf-9570-4ee1-98c5-8a78f59c7956\\\"\\n/>\\n</details>\\n\\n##\nTesting\\n\\nI
thoroughly tested with `DiffMethod.WORDS_WITH_SPACE`
across\nvarious\\ninputs and scenarios, including:\\n- Single-line and
multi-line\nstrings.\\n- Numbers, arrays, and objects.\\n- Additions,
deletions, and\nupdates at different positions (start,\\nmiddle, and
end) within and\nacross lines.\\n\\nI also validated diffs against real
prebuilt rules by\ninstalling an\\nolder Fleet package version and
observed no\nissues.\\n\\nYou can test by trying different input strings
and settings\nin\\nStorybook.\\n**Run Storybook**: `yarn
storybook\nsecurity_solution`.\\n\\n\\nhttps://github.com/user-attachments/assets/0440b73c-a4d7-40cf-9cee-e632146d292e\\n\\nYou\ncan
notice that `ComparisonSide` stories are broken, but\nthat's\\nunrelated
to these changes and needs to be handled\nseparately.\\n\\n##
Compatibility with future upgrades\\n\\nThere's an
open\n[PR](#202622) that\\nwill
upgrade\nthe `diff` library from v5 to v7. I verified the
behavior\\nof\n`DiffMethod.WORDS_WITH_SPACE` on v7 and found no
differences\ncompared\\nto v5, so it should be safe to upgrade to v7
without any\nchanges on our\\nend.\\n\\nWork started
on\n23-Dec-2024.\",\"sha\":\"140c2e0ecf9f8a0277699052f9ba472066a0e96d\",\"branchLabelMapping\":{\"^v9.0.0$\":\"main\",\"^v8.18.0$\":\"8.x\",\"^v(\\\\d+).(\\\\d+).\\\\d+$\":\"$1.$2\"}},\"sourcePullRequest\":{\"labels\":[\"release_note:skip\",\"v9.0.0\",\"Team:Detections\nand
Resp\",\"Team:
SecuritySolution\",\"Feature:Rule\nManagement\",\"Team:Detection Rule
Management\",\"Feature:Prebuilt
Detection\nRules\",\"backport:version\",\"v8.18.0\"],\"title\":\"[Security
Solution] Fix\nincorrect changes highlighting in
diff\nview\",\"number\":205138,\"url\":\"https://github.com/elastic/kibana/pull/205138\",\"mergeCommit\":{\"message\":\"[Security\nSolution]
Fix incorrect changes highlighting in diff
view\n(#205138)\\n\\n**Resolves:\nhttps://github.com//issues/202016**\\n\\n##
Summary\\n\\nThis\nPR resolves an issue where the diff view incorrectly
marked\ncertain\\ncharacters as changed (using bold font) in some
cases.\\n\\n##\nRoot Cause\\nThe issue arises from a bug in the `diff`
library (v5). The\nlibrary is\\nused to compute two-way diffs between
strings (old field\nvalue and new\\nfield value), producing an array of
change objects that\nis then used for\\nrendering.\\n\\nConditions for
the bug:\\n- `diff` v5\nlibrary is in use (fixed in v6 and above)
and\\n`DiffMethod.WORDS` is\npassed as a parameter to it.\\n- The old
field value contains a line with\nan addition separated by a\\nspace
(see example below).\\n- The next line\ncontains some changes
(additions, deletions, or\\nupdates).\\n\\n\\nFor\nexample, for these
input
strings:\\n```\\nfoo\nbar\\nspring\\n```\\n```\\nfoo\\nsprint\\n```\\n\\n|
You would expect to see\nthis diff | But you actually see this
|\\n|----------|----------|\\n|
<img\nwidth=\\\"119\\\"\nalt=\\\"expected\\\"\\nsrc=\\\"https://github.com/user-attachments/assets/c41b3dec-e578-4a12-8eb8-91fbb60d7247\\\"\\n/>\n|
<img
width=\\\"118\\\"\nalt=\\\"actual\\\"\\nsrc=\\\"https://github.com/user-attachments/assets/f2a33fee-5de2-4291-876a-e7575ea07079\\\"\\n/>\n|\\n\\n**A
more real-life example**\\n<img
width=\\\"1661\\\"\nalt=\\\"more_real_life\\\"\\nsrc=\\\"https://github.com/user-attachments/assets/91ebfe93-81ad-45c8-8f9b-e173c2cf940b\\\"\\n/>\\n\\n\\n##\nSolution\\nSwitching
to `DiffMethod.WORDS_WITH_SPACE` avoids this issue.\n\\nScreenshot
showing the difference between
`DiffMethod.WORDS`\nand\\n`DiffMethod.WORDS_WITH_SPACE`:\\n<img
width=\\\"675\\\"\nalt=\\\"words_vs_words_with_space\\\"\\nsrc=\\\"https://github.com/user-attachments/assets/3c91e1d2-63fc-4fcd-a762-a905878bfc3a\\\"\\n/>\\n\\n##\nOther
changes\\n- Removed `DiffMethod.TRIMMED_LINES` since
it's\nnow\\n[deprecated](kpdecker/jsdiff#486) in
the\n`diff`\\nlibrary and we are not using it anyways.\\n- Stopped using
the\n\\\"zip\\\" option since I believe it produces a less\\nreadable
diff,\nespecially for cases when there's a different number of\\nlines
in the\noriginal value vs
updated\nvalue.\\n\\n<details>\\n<summary><strong>Screenshots: with and
without\n\\\"zip\\\" (click
to\\nexpand)</strong></summary>\\n<strong>With the \\\"zip\\\"\noption
(how it was before)</strong>\\n<img
width=\\\"1918\\\"\nalt=\\\"zip\\\"\\nsrc=\\\"https://github.com/user-attachments/assets/272ed849-47d6-4fef-8acc-ab1b22c9f42e\\\"\\n/>\\n\\n<strong>No\n\\\"zip\\\"
(this branch)</strong>\\n<img
width=\\\"1919\\\"\nalt=\\\"no_zip\\\"\\nsrc=\\\"https://github.com/user-attachments/assets/417303bf-9570-4ee1-98c5-8a78f59c7956\\\"\\n/>\\n</details>\\n\\n##\nTesting\\n\\nI
thoroughly tested with `DiffMethod.WORDS_WITH_SPACE`
across\nvarious\\ninputs and scenarios, including:\\n- Single-line and
multi-line\nstrings.\\n- Numbers, arrays, and objects.\\n- Additions,
deletions, and\nupdates at different positions (start,\\nmiddle, and
end) within and\nacross lines.\\n\\nI also validated diffs against real
prebuilt rules by\ninstalling an\\nolder Fleet package version and
observed no\nissues.\\n\\nYou can test by trying different input strings
and settings\nin\\nStorybook.\\n**Run Storybook**: `yarn
storybook\nsecurity_solution`.\\n\\n\\nhttps://github.com/user-attachments/assets/0440b73c-a4d7-40cf-9cee-e632146d292e\\n\\nYou\ncan
notice that `ComparisonSide` stories are broken, but\nthat's\\nunrelated
to these changes and needs to be handled\nseparately.\\n\\n##
Compatibility with future upgrades\\n\\nThere's an
open\n[PR](#202622) that\\nwill
upgrade\nthe `diff` library from v5 to v7. I verified the
behavior\\nof\n`DiffMethod.WORDS_WITH_SPACE` on v7 and found no
differences\ncompared\\nto v5, so it should be safe to upgrade to v7
without any\nchanges on our\\nend.\\n\\nWork started
on\n23-Dec-2024.\",\"sha\":\"140c2e0ecf9f8a0277699052f9ba472066a0e96d\"}},\"sourceBranch\":\"main\",\"suggestedTargetBranches\":[\"8.x\"],\"targetPullRequestStates\":[{\"branch\":\"main\",\"label\":\"v9.0.0\",\"branchLabelMappingKey\":\"^v9.0.0$\",\"isSourceBranch\":true,\"state\":\"MERGED\",\"url\":\"https://github.com/elastic/kibana/pull/205138\",\"number\":205138,\"mergeCommit\":{\"message\":\"[Security\nSolution]
Fix incorrect changes highlighting in diff
view\n(#205138)\\n\\n**Resolves:\nhttps://github.com//issues/202016**\\n\\n##
Summary\\n\\nThis\nPR resolves an issue where the diff view incorrectly
marked\ncertain\\ncharacters as changed (using bold font) in some
cases.\\n\\n##\nRoot Cause\\nThe issue arises from a bug in the `diff`
library (v5). The\nlibrary is\\nused to compute two-way diffs between
strings (old field\nvalue and new\\nfield value), producing an array of
change objects that\nis then used for\\nrendering.\\n\\nConditions for
the bug:\\n- `diff` v5\nlibrary is in use (fixed in v6 and above)
and\\n`DiffMethod.WORDS` is\npassed as a parameter to it.\\n- The old
field value contains a line with\nan addition separated by a\\nspace
(see example below).\\n- The next line\ncontains some changes
(additions, deletions, or\\nupdates).\\n\\n\\nFor\nexample, for these
input
strings:\\n```\\nfoo\nbar\\nspring\\n```\\n```\\nfoo\\nsprint\\n```\\n\\n|
You would expect to see\nthis diff | But you actually see this
|\\n|----------|----------|\\n|
<img\nwidth=\\\"119\\\"\nalt=\\\"expected\\\"\\nsrc=\\\"https://github.com/user-attachments/assets/c41b3dec-e578-4a12-8eb8-91fbb60d7247\\\"\\n/>\n|
<img
width=\\\"118\\\"\nalt=\\\"actual\\\"\\nsrc=\\\"https://github.com/user-attachments/assets/f2a33fee-5de2-4291-876a-e7575ea07079\\\"\\n/>\n|\\n\\n**A
more real-life example**\\n<img
width=\\\"1661\\\"\nalt=\\\"more_real_life\\\"\\nsrc=\\\"https://github.com/user-attachments/assets/91ebfe93-81ad-45c8-8f9b-e173c2cf940b\\\"\\n/>\\n\\n\\n##\nSolution\\nSwitching
to `DiffMethod.WORDS_WITH_SPACE` avoids this issue.\n\\nScreenshot
showing the difference between
`DiffMethod.WORDS`\nand\\n`DiffMethod.WORDS_WITH_SPACE`:\\n<img
width=\\\"675\\\"\nalt=\\\"words_vs_words_with_space\\\"\\nsrc=\\\"https://github.com/user-attachments/assets/3c91e1d2-63fc-4fcd-a762-a905878bfc3a\\\"\\n/>\\n\\n##\nOther
changes\\n- Removed `DiffMethod.TRIMMED_LINES` since
it's\nnow\\n[deprecated](kpdecker/jsdiff#486) in
the\n`diff`\\nlibrary and we are not using it anyways.\\n- Stopped using
the\n\\\"zip\\\" option since I believe it produces a less\\nreadable
diff,\nespecially for cases when there's a different number of\\nlines
in the\noriginal value vs
updated\nvalue.\\n\\n<details>\\n<summary><strong>Screenshots: with and
without\n\\\"zip\\\" (click
to\\nexpand)</strong></summary>\\n<strong>With the \\\"zip\\\"\noption
(how it was before)</strong>\\n<img
width=\\\"1918\\\"\nalt=\\\"zip\\\"\\nsrc=\\\"https://github.com/user-attachments/assets/272ed849-47d6-4fef-8acc-ab1b22c9f42e\\\"\\n/>\\n\\n<strong>No\n\\\"zip\\\"
(this branch)</strong>\\n<img
width=\\\"1919\\\"\nalt=\\\"no_zip\\\"\\nsrc=\\\"https://github.com/user-attachments/assets/417303bf-9570-4ee1-98c5-8a78f59c7956\\\"\\n/>\\n</details>\\n\\n##\nTesting\\n\\nI
thoroughly tested with `DiffMethod.WORDS_WITH_SPACE`
across\nvarious\\ninputs and scenarios, including:\\n- Single-line and
multi-line\nstrings.\\n- Numbers, arrays, and objects.\\n- Additions,
deletions, and\nupdates at different positions (start,\\nmiddle, and
end) within and\nacross lines.\\n\\nI also validated diffs against real
prebuilt rules by\ninstalling an\\nolder Fleet package version and
observed no\nissues.\\n\\nYou can test by trying different input strings
and settings\nin\\nStorybook.\\n**Run Storybook**: `yarn
storybook\nsecurity_solution`.\\n\\n\\nhttps://github.com/user-attachments/assets/0440b73c-a4d7-40cf-9cee-e632146d292e\\n\\nYou\ncan
notice that `ComparisonSide` stories are broken, but\nthat's\\nunrelated
to these changes and needs to be handled\nseparately.\\n\\n##
Compatibility with future upgrades\\n\\nThere's an
open\n[PR](#202622) that\\nwill
upgrade\nthe `diff` library from v5 to v7. I verified the
behavior\\nof\n`DiffMethod.WORDS_WITH_SPACE` on v7 and found no
differences\ncompared\\nto v5, so it should be safe to upgrade to v7
without any\nchanges on our\\nend.\\n\\nWork started
on\n23-Dec-2024.\",\"sha\":\"140c2e0ecf9f8a0277699052f9ba472066a0e96d\"}},{\"branch\":\"8.x\",\"label\":\"v8.18.0\",\"branchLabelMappingKey\":\"^v8.18.0$\",\"isSourceBranch\":false,\"state\":\"NOT_CREATED\"}]}]\nBACKPORT-->\n\nCo-authored-by:
Nikita Indik <nikita.indik@elastic.co>"}}]}] BACKPORT-->
@davismcphee davismcphee added backport:prev-minor Backport to (8.x) the previous minor version (i.e. one version back from main) and removed backport:all-open Backport to all branches that could still receive a release labels Jan 6, 2025
@elasticmachine
Copy link
Contributor

💛 Build succeeded, but was flaky

Failed CI Steps

Test Failures

  • [job] [logs] FTR Configs #41 / serverless observability UI Dataset Quality Dataset quality summary shows poor, degraded and good count as 0 and all dataset as healthy

Metrics [docs]

Module Count

Fewer modules leads to a faster build time

id before after diff
securitySolution 6488 6489 +1

Async chunks

Total size of all lazy-loaded chunks that will be downloaded as the user navigates the app

id before after diff
cloudSecurityPosture 499.0KB 505.9KB +7.0KB
discover 778.0KB 785.0KB +7.0KB
esqlDataGrid 153.8KB 160.7KB +7.0KB
securitySolution 22.1MB 22.1MB +31.1KB
slo 831.7KB 838.7KB +7.0KB
total +59.0KB

Page load bundle

Size of the bundles that are downloaded on every page load. Target size is below 100kb

id before after diff
kbnUiSharedDeps-npmDll 5.9MB 5.9MB +51.0B

History

cc @davismcphee

@davismcphee davismcphee merged commit 90e738f into main Jan 6, 2025
11 checks passed
@davismcphee davismcphee deleted the renovate/main-@elastickibana-data-discovery-dependencies branch January 6, 2025 19:26
@kibanamachine
Copy link
Contributor

Starting backport for target branches: 8.x

https://github.com/elastic/kibana/actions/runs/12638990463

kibanamachine pushed a commit to kibanamachine/kibana that referenced this pull request Jan 6, 2025
…2622)

This PR contains the following updates:

| Package | Type | Update | Change |
|---|---|---|---|
|
[@types/diff](https://togithub.com/DefinitelyTyped/DefinitelyTyped/tree/master/types/diff)
([source](https://togithub.com/DefinitelyTyped/DefinitelyTyped/tree/HEAD/types/diff))
| devDependencies | major | [`^5.0.8` ->
`^6.0.0`](https://renovatebot.com/diffs/npm/@types%2fdiff/5.0.8/6.0.0) |
| [diff](https://togithub.com/kpdecker/jsdiff) | dependencies | major |
[`^5.1.0` ->
`^7.0.0`](https://renovatebot.com/diffs/npm/diff/5.1.0/7.0.0) |
|
[fastest-levenshtein](https://togithub.com/ka-weihe/fastest-levenshtein)
| dependencies | patch | [`^1.0.12` ->
`^1.0.16`](https://renovatebot.com/diffs/npm/fastest-levenshtein/1.0.12/1.0.16)
|

---

### Release Notes

<details>
<summary>kpdecker/jsdiff (diff)</summary>

###
[`v7.0.0`](https://togithub.com/kpdecker/jsdiff/blob/HEAD/release-notes.md#700)

[Compare
Source](https://togithub.com/kpdecker/jsdiff/compare/v6.0.0...7.0.0)

Just a single (breaking) bugfix, undoing a behaviour change introduced
accidentally in 6.0.0:

- [#&elastic#8203;554](https://togithub.com/kpdecker/jsdiff/pull/554)
**`diffWords` treats numbers and underscores as word characters again.**
This behaviour was broken in v6.0.0.

###
[`v6.0.0`](https://togithub.com/kpdecker/jsdiff/blob/HEAD/release-notes.md#600)

[Compare
Source](https://togithub.com/kpdecker/jsdiff/compare/v5.2.0...v6.0.0)

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.

[Commits](https://togithub.com/kpdecker/jsdiff/compare/v5.2.0...v6.0.0)

- [#&elastic#8203;497](https://togithub.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.

    Runs of whitespace are still tokens in `diffWordsWithSpace`.

As part of the changes to `diffWords`, **a new `.postProcess` method has
been added on the base `Diff` type**, which can be overridden in custom
`Diff` implementations.

**`diffLines` with `ignoreWhitespace: true` will no longer ignore the
insertion or deletion of entire extra lines of whitespace at the end of
the text**. Previously, these would not show up as insertions or
deletions, as a side effect of a hack in the base diffing algorithm
meant to help ignore whitespace in `diffWords`. More generally, **the
undocumented special handling in the core algorithm for ignored
terminals has been removed entirely.** (This special case behavior used
to rewrite the final two change objects in a scenario where the final
change object was an addition or deletion and its `value` was treated as
equal to the empty string when compared using the diff object's
`.equals` method.)

- [#&elastic#8203;500](https://togithub.com/kpdecker/jsdiff/pull/500)
**`diffChars` now diffs Unicode code points** instead of UTF-16 code
units.

- [#&elastic#8203;508](https://togithub.com/kpdecker/jsdiff/pull/508)
**`parsePatch` now always runs in what was previously "strict" mode; the
undocumented `strict` option has been removed.** Previously, by default,
`parsePatch` (and other patch functions that use it under the hood to
parse patches) would accept a patch where the line counts in the headers
were inconsistent with the actual patch content - e.g. where a hunk
started with the header `@@&elastic#8203; -1,3 +1,6 @&elastic#8203;@&elastic#8203;`,
indicating that the content below spanned 3 lines in the old file and 6
lines in the new file, but then the actual content below the header
consisted of some different number of lines, say 10 lines of context, 5
deletions, and 1 insertion. Actually trying to work with these patches
using `applyPatch` or `merge`, however, would produce incorrect results
instead of just ignoring the incorrect headers, making this "feature"
more of a trap than something actually useful. It's been ripped out, and
now we are always "strict" and will reject patches where the line counts
in the headers aren't consistent with the actual patch content.

- [#&elastic#8203;435](https://togithub.com/kpdecker/jsdiff/pull/435) **Fix
`parsePatch` handling of control characters.** `parsePatch` used to
interpret various unusual control characters - namely vertical tabs,
form feeds, lone carriage returns without a line feed, and EBCDIC NELs -
as line breaks when parsing a patch file. This was inconsistent with the
behavior of both JsDiff's own `diffLines` method and also the Unix
`diff` and `patch` utils, which all simply treat those control
characters as ordinary characters. The result of this discrepancy was
that some well-formed patches - produced either by `diff` or by JsDiff
itself and handled properly by the `patch` util - would be wrongly
parsed by `parsePatch`, with the effect that it would disregard the
remainder of a hunk after encountering one of these control characters.

- [#&elastic#8203;439](https://togithub.com/kpdecker/jsdiff/pull/439) **Prefer
diffs that order deletions before insertions.** When faced with a choice
between two diffs with an equal total edit distance, the Myers diff
algorithm generally prefers one that does deletions before insertions
rather than insertions before deletions. For instance, when diffing
`abcd` against `acbd`, it will prefer a diff that says to delete the `b`
and then insert a new `b` after the `c`, over a diff that says to insert
a `c` before the `b` and then delete the existing `c`. JsDiff deviated
from the published Myers algorithm in a way that led to it having the
opposite preference in many cases, including that example. This is now
fixed, meaning diffs output by JsDiff will more accurately reflect what
the published Myers diff algorithm would output.

- [#&elastic#8203;455](https://togithub.com/kpdecker/jsdiff/pull/455) **The
`added` and `removed` properties of change objects are now guaranteed to
be set to a boolean value.** (Previously, they would be set to
`undefined` or omitted entirely instead of setting them to false.)

- [#&elastic#8203;464](https://togithub.com/kpdecker/jsdiff/pull/464)
Specifying `{maxEditLength: 0}` now sets a max edit length of 0 instead
of no maximum.

- [#&elastic#8203;460](https://togithub.com/kpdecker/jsdiff/pull/460) **Added
`oneChangePerToken` option.**

- [#&elastic#8203;467](https://togithub.com/kpdecker/jsdiff/pull/467)
**Consistent ordering of arguments to `comparator(left, right)`.**
Values from the old array will now consistently be passed as the first
argument (`left`) and values from the new array as the second argument
(`right`). Previously this was almost (but not quite) always the other
way round.

- [#&elastic#8203;480](https://togithub.com/kpdecker/jsdiff/pull/480) **Passing
`maxEditLength` to `createPatch` & `createTwoFilesPatch` now works
properly** (i.e. returns undefined if the max edit distance is exceeded;
previous behavior was to crash with a `TypeError` if the edit distance
was exceeded).

- [#&elastic#8203;486](https://togithub.com/kpdecker/jsdiff/pull/486) **The
`ignoreWhitespace` option of `diffLines` behaves more sensibly now.**
`value`s in returned change objects now include leading/trailing
whitespace even when `ignoreWhitespace` is used, just like how with
`ignoreCase` the `value`s still reflect the case of one of the original
texts instead of being all-lowercase. `ignoreWhitespace` is also now
compatible with `newlineIsToken`. Finally, **`diffTrimmedLines` is
deprecated** (and removed from the docs) in favour of using `diffLines`
with `ignoreWhitespace: true`; the two are, and always have been,
equivalent.

- [#&elastic#8203;490](https://togithub.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`.)

- [#&elastic#8203;489](togithub.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`.

- [#&elastic#8203;518](https://togithub.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.

- [#&elastic#8203;521](https://togithub.com/kpdecker/jsdiff/pull/521) **the
`callback` option is now supported by `structuredPatch`, `createPatch`,
and `createTwoFilesPatch`**

- [#&elastic#8203;529](https://togithub.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.

- [#&elastic#8203;530](https://togithub.com/kpdecker/jsdiff/pull/530) **Added
`ignoreNewlineAtEof` option to `diffLines`**

- [#&elastic#8203;533](https://togithub.com/kpdecker/jsdiff/pull/533)
**`applyPatch` uses an entirely new algorithm for fuzzy matching.**
Differences between the old and new algorithm are as follows:
- 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`.)
- 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.)
- The context line immediately before and immediately after an insertion
must match exactly between the hunk and the file for a hunk to apply.
(Previously this was not required.)

- [#&elastic#8203;535](https://togithub.com/kpdecker/jsdiff/pull/535) **A bug
in patch generation functions is now fixed** that would sometimes
previously cause `\ No newline at end of file` to appear in the wrong
place in the generated patch, resulting in the patch being invalid.

- [#&elastic#8203;535](https://togithub.com/kpdecker/jsdiff/pull/535) **Passing
`newlineIsToken: true` to *patch*-generation functions is no longer
allowed.** (Passing it to `diffLines` is still supported - it's only
functions like `createPatch` where passing `newlineIsToken` is now an
error.) Allowing it to be passed never really made sense, since in cases
where the option had any effect on the output at all, the effect tended
to be causing a garbled patch to be created that couldn't actually be
applied to the source file.

- [#&elastic#8203;539](https://togithub.com/kpdecker/jsdiff/pull/539)
**`diffWords` now takes an optional `intlSegmenter` option** which
should be an `Intl.Segmenter` with word-level granularity. This provides
better tokenization of text into words than the default behaviour, even
for English but especially for some other languages for which the
default behaviour is poor.

###
[`v5.2.0`](https://togithub.com/kpdecker/jsdiff/blob/HEAD/release-notes.md#v520)

[Compare
Source](https://togithub.com/kpdecker/jsdiff/compare/v5.1.0...v5.2.0)

[Commits](https://togithub.com/kpdecker/jsdiff/compare/v5.1.0...v5.2.0)

- [#&elastic#8203;411](https://togithub.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.
- [#&elastic#8203;448](https://togithub.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.
- [#&elastic#8203;351](https://togithub.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.
- [#&elastic#8203;344](https://togithub.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.
- [#&elastic#8203;451](https://togithub.com/kpdecker/jsdiff/pull/451) Added
`diff.formatPatch`.
- [#&elastic#8203;450](https://togithub.com/kpdecker/jsdiff/pull/450) Added
`diff.reversePatch`.
- [#&elastic#8203;478](https://togithub.com/kpdecker/jsdiff/pull/478) Added
`timeout` option.

</details>

<details>
<summary>ka-weihe/fastest-levenshtein (fastest-levenshtein)</summary>

###
[`v1.0.16`](https://togithub.com/ka-weihe/fastest-levenshtein/compare/1.0.15...03d621ba324d0f665b3b7f557429ca622560d9a3)

[Compare
Source](https://togithub.com/ka-weihe/fastest-levenshtein/compare/1.0.15...03d621ba324d0f665b3b7f557429ca622560d9a3)

###
[`v1.0.15`](https://togithub.com/ka-weihe/fastest-levenshtein/compare/37bd0917de8347c73d67467bd1c5ea803cba5f94...1.0.15)

[Compare
Source](https://togithub.com/ka-weihe/fastest-levenshtein/compare/37bd0917de8347c73d67467bd1c5ea803cba5f94...1.0.15)

###
[`v1.0.14`](https://togithub.com/ka-weihe/fastest-levenshtein/compare/45d58d245e0d75138bb7da00dd1188ef8d6fdb84...37bd0917de8347c73d67467bd1c5ea803cba5f94)

[Compare
Source](https://togithub.com/ka-weihe/fastest-levenshtein/compare/45d58d245e0d75138bb7da00dd1188ef8d6fdb84...37bd0917de8347c73d67467bd1c5ea803cba5f94)

###
[`v1.0.13`](https://togithub.com/ka-weihe/fastest-levenshtein/compare/606c132c58039c22989fa0d2d91d4e2d8bbb2404...45d58d245e0d75138bb7da00dd1188ef8d6fdb84)

[Compare
Source](https://togithub.com/ka-weihe/fastest-levenshtein/compare/606c132c58039c22989fa0d2d91d4e2d8bbb2404...45d58d245e0d75138bb7da00dd1188ef8d6fdb84)

</details>

---

### Configuration

📅 **Schedule**: Branch creation - At any time (no schedule defined),
Automerge - At any time (no schedule defined).

🚦 **Automerge**: Disabled by config. Please merge this manually once you
are satisfied.

♻ **Rebasing**: Whenever PR becomes conflicted, or you tick the
rebase/retry checkbox.

👻 **Immortal**: This PR will be recreated if closed unmerged. Get
[config help](https://togithub.com/renovatebot/renovate/discussions) if
that's undesired.

---

- [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check
this box

---

This PR has been generated by [Renovate
Bot](https://togithub.com/renovatebot/renovate).

<!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiIzNy40MjUuMSIsInVwZGF0ZWRJblZlciI6IjM3LjQyNS4xIiwidGFyZ2V0QnJhbmNoIjoibWFpbiIsImxhYmVscyI6WyJUZWFtOkRhdGFEaXNjb3ZlcnkiLCJiYWNrcG9ydDphbGwtb3BlbiIsInJlbGVhc2Vfbm90ZTpza2lwIl19-->

---------

Co-authored-by: elastic-renovate-prod[bot] <174716857+elastic-renovate-prod[bot]@users.noreply.github.com>
Co-authored-by: kibanamachine <42973632+kibanamachine@users.noreply.github.com>
Co-authored-by: Davis McPhee <davis.mcphee@elastic.co>
Co-authored-by: Nikita Indik <nikita.indik@elastic.co>
Co-authored-by: Matthias Wilhelm <matthias.wilhelm@elastic.co>
(cherry picked from commit 90e738f)
@kibanamachine
Copy link
Contributor

💚 All backports created successfully

Status Branch Result
8.x

Note: Successful backport PRs will be merged automatically after passing CI.

Questions ?

Please refer to the Backport tool documentation

kibanamachine added a commit that referenced this pull request Jan 7, 2025
) (#205647)

# Backport

This will backport the following commits from `main` to `8.x`:
- [Update @elastic/kibana-data-discovery dependencies (main)
(#202622)](https://github.com/elastic/kibana/pull/202622)

<!--- Backport version: 9.4.3 -->

### Questions ?
Please refer to the [Backport tool
documentation](https://github.com/sqren/backport)

<!--BACKPORT
[{"author":{"name":"elastic-renovate-prod[bot]","email":"174716857+elastic-renovate-prod[bot]@users.noreply.github.com"},"sourceCommit":{"committedDate":"2025-01-06T19:26:30Z","message":"Update
@elastic/kibana-data-discovery dependencies (main) (#202622)\n\nThis PR
contains the following updates:\r\n\r\n| Package | Type | Update |
Change
|\r\n|---|---|---|---|\r\n|\r\n[@types/diff](https://togithub.com/DefinitelyTyped/DefinitelyTyped/tree/master/types/diff)\r\n([source](https://togithub.com/DefinitelyTyped/DefinitelyTyped/tree/HEAD/types/diff))\r\n|
devDependencies | major | [`^5.0.8`
->\r\n`^6.0.0`](https://renovatebot.com/diffs/npm/@types%2fdiff/5.0.8/6.0.0)
|\r\n| [diff](https://togithub.com/kpdecker/jsdiff) | dependencies |
major |\r\n[`^5.1.0`
->\r\n`^7.0.0`](https://renovatebot.com/diffs/npm/diff/5.1.0/7.0.0)
|\r\n|\r\n[fastest-levenshtein](https://togithub.com/ka-weihe/fastest-levenshtein)\r\n|
dependencies | patch | [`^1.0.12`
->\r\n`^1.0.16`](https://renovatebot.com/diffs/npm/fastest-levenshtein/1.0.12/1.0.16)\r\n|\r\n\r\n---\r\n\r\n###
Release Notes\r\n\r\n<details>\r\n<summary>kpdecker/jsdiff
(diff)</summary>\r\n\r\n###\r\n[`v7.0.0`](https://togithub.com/kpdecker/jsdiff/blob/HEAD/release-notes.md#700)\r\n\r\n[Compare\r\nSource](https://togithub.com/kpdecker/jsdiff/compare/v6.0.0...7.0.0)\r\n\r\nJust
a single (breaking) bugfix, undoing a behaviour change
introduced\r\naccidentally in 6.0.0:\r\n\r\n-
[#&#8203;554](https://togithub.com/kpdecker/jsdiff/pull/554)\r\n**`diffWords`
treats numbers and underscores as word characters again.**\r\nThis
behaviour was broken in
v6.0.0.\r\n\r\n###\r\n[`v6.0.0`](https://togithub.com/kpdecker/jsdiff/blob/HEAD/release-notes.md#600)\r\n\r\n[Compare\r\nSource](https://togithub.com/kpdecker/jsdiff/compare/v5.2.0...v6.0.0)\r\n\r\nThis
is a release containing many, *many* breaking changes. The\r\nobjective
of this release was to carry out a mass fix, in one go, of all\r\nthe
open bugs and design problems that required breaking changes to
fix.\r\nA substantial, but exhaustive, changelog is
below.\r\n\r\n[Commits](https://togithub.com/kpdecker/jsdiff/compare/v5.2.0...v6.0.0)\r\n\r\n-
[#&#8203;497](https://togithub.com/kpdecker/jsdiff/pull/497)\r\n**`diffWords`
behavior has been radically changed.** Previously, even\r\nwith
`ignoreWhitespace: true`, runs of whitespace were tokens, which
led\r\nto unhelpful and unintuitive diffing behavior in typical
texts.\r\nSpecifically, even when two texts contained overlapping
passages,\r\n`diffWords` would sometimes choose to delete all the words
from the old\r\ntext and insert them anew in their new positions in
order to avoid\r\nhaving to delete or insert whitespace tokens.
Whitespace sequences are\r\nno longer tokens as of this release, which
affects both the generated\r\ndiffs and the `count`s.\r\n\r\n Runs of
whitespace are still tokens in `diffWordsWithSpace`.\r\n\r\nAs part of
the changes to `diffWords`, **a new `.postProcess` method has\r\nbeen
added on the base `Diff` type**, which can be overridden in
custom\r\n`Diff` implementations.\r\n\r\n**`diffLines` with
`ignoreWhitespace: true` will no longer ignore the\r\ninsertion or
deletion of entire extra lines of whitespace at the end of\r\nthe
text**. Previously, these would not show up as insertions
or\r\ndeletions, as a side effect of a hack in the base diffing
algorithm\r\nmeant to help ignore whitespace in `diffWords`. More
generally, **the\r\nundocumented special handling in the core algorithm
for ignored\r\nterminals has been removed entirely.** (This special case
behavior used\r\nto rewrite the final two change objects in a scenario
where the final\r\nchange object was an addition or deletion and its
`value` was treated as\r\nequal to the empty string when compared using
the diff object's\r\n`.equals` method.)\r\n\r\n-
[#&#8203;500](https://togithub.com/kpdecker/jsdiff/pull/500)\r\n**`diffChars`
now diffs Unicode code points** instead of UTF-16
code\r\nunits.\r\n\r\n-
[#&#8203;508](https://togithub.com/kpdecker/jsdiff/pull/508)\r\n**`parsePatch`
now always runs in what was previously \"strict\" mode;
the\r\nundocumented `strict` option has been removed.** Previously, by
default,\r\n`parsePatch` (and other patch functions that use it under
the hood to\r\nparse patches) would accept a patch where the line counts
in the headers\r\nwere inconsistent with the actual patch content - e.g.
where a hunk\r\nstarted with the header `@@&#8203; -1,3 +1,6
@&#8203;@&#8203;`,\r\nindicating that the content below spanned 3 lines
in the old file and 6\r\nlines in the new file, but then the actual
content below the header\r\nconsisted of some different number of lines,
say 10 lines of context, 5\r\ndeletions, and 1 insertion. Actually
trying to work with these patches\r\nusing `applyPatch` or `merge`,
however, would produce incorrect results\r\ninstead of just ignoring the
incorrect headers, making this \"feature\"\r\nmore of a trap than
something actually useful. It's been ripped out, and\r\nnow we are
always \"strict\" and will reject patches where the line counts\r\nin
the headers aren't consistent with the actual patch content.\r\n\r\n-
[#&#8203;435](https://togithub.com/kpdecker/jsdiff/pull/435)
**Fix\r\n`parsePatch` handling of control characters.** `parsePatch`
used to\r\ninterpret various unusual control characters - namely
vertical tabs,\r\nform feeds, lone carriage returns without a line feed,
and EBCDIC NELs -\r\nas line breaks when parsing a patch file. This was
inconsistent with the\r\nbehavior of both JsDiff's own `diffLines`
method and also the Unix\r\n`diff` and `patch` utils, which all simply
treat those control\r\ncharacters as ordinary characters. The result of
this discrepancy was\r\nthat some well-formed patches - produced either
by `diff` or by JsDiff\r\nitself and handled properly by the `patch`
util - would be wrongly\r\nparsed by `parsePatch`, with the effect that
it would disregard the\r\nremainder of a hunk after encountering one of
these control characters.\r\n\r\n-
[#&#8203;439](https://togithub.com/kpdecker/jsdiff/pull/439)
**Prefer\r\ndiffs that order deletions before insertions.** When faced
with a choice\r\nbetween two diffs with an equal total edit distance,
the Myers diff\r\nalgorithm generally prefers one that does deletions
before insertions\r\nrather than insertions before deletions. For
instance, when diffing\r\n`abcd` against `acbd`, it will prefer a diff
that says to delete the `b`\r\nand then insert a new `b` after the `c`,
over a diff that says to insert\r\na `c` before the `b` and then delete
the existing `c`. JsDiff deviated\r\nfrom the published Myers algorithm
in a way that led to it having the\r\nopposite preference in many cases,
including that example. This is now\r\nfixed, meaning diffs output by
JsDiff will more accurately reflect what\r\nthe published Myers diff
algorithm would output.\r\n\r\n-
[#&#8203;455](https://togithub.com/kpdecker/jsdiff/pull/455)
**The\r\n`added` and `removed` properties of change objects are now
guaranteed to\r\nbe set to a boolean value.** (Previously, they would be
set to\r\n`undefined` or omitted entirely instead of setting them to
false.)\r\n\r\n-
[#&#8203;464](https://togithub.com/kpdecker/jsdiff/pull/464)\r\nSpecifying
`{maxEditLength: 0}` now sets a max edit length of 0 instead\r\nof no
maximum.\r\n\r\n-
[#&#8203;460](https://togithub.com/kpdecker/jsdiff/pull/460)
**Added\r\n`oneChangePerToken` option.**\r\n\r\n-
[#&#8203;467](https://togithub.com/kpdecker/jsdiff/pull/467)\r\n**Consistent
ordering of arguments to `comparator(left, right)`.**\r\nValues from the
old array will now consistently be passed as the first\r\nargument
(`left`) and values from the new array as the second
argument\r\n(`right`). Previously this was almost (but not quite) always
the other\r\nway round.\r\n\r\n-
[#&#8203;480](https://togithub.com/kpdecker/jsdiff/pull/480)
**Passing\r\n`maxEditLength` to `createPatch` & `createTwoFilesPatch`
now works\r\nproperly** (i.e. returns undefined if the max edit distance
is exceeded;\r\nprevious behavior was to crash with a `TypeError` if the
edit distance\r\nwas exceeded).\r\n\r\n-
[#&#8203;486](https://togithub.com/kpdecker/jsdiff/pull/486)
**The\r\n`ignoreWhitespace` option of `diffLines` behaves more sensibly
now.**\r\n`value`s in returned change objects now include
leading/trailing\r\nwhitespace even when `ignoreWhitespace` is used,
just like how with\r\n`ignoreCase` the `value`s still reflect the case
of one of the original\r\ntexts instead of being all-lowercase.
`ignoreWhitespace` is also now\r\ncompatible with `newlineIsToken`.
Finally, **`diffTrimmedLines` is\r\ndeprecated** (and removed from the
docs) in favour of using `diffLines`\r\nwith `ignoreWhitespace: true`;
the two are, and always have been,\r\nequivalent.\r\n\r\n-
[#&#8203;490](https://togithub.com/kpdecker/jsdiff/pull/490)
**When\r\ncalling diffing functions in async mode by passing a
`callback` option,\r\nthe diff result will now be passed as the *first*
argument to the\r\ncallback instead of the second.** (Previously, the
first argument was\r\nnever used at all and would always have value
`undefined`.)\r\n\r\n-
[#&#8203;489](togithub.com/kpdecker/jsdiff/pull/489)
**`this.options`\r\nno longer exists on `Diff` objects.** Instead,
`options` is now passed\r\nas an argument to methods that rely on
options, like `equals(left,\r\nright, options)`. This fixes a race
condition in async mode, where\r\ndiffing behaviour could be changed
mid-execution if a concurrent usage\r\nof the same `Diff` instances
overwrote its `options`.\r\n\r\n-
[#&#8203;518](https://togithub.com/kpdecker/jsdiff/pull/518)\r\n**`linedelimiters`
no longer exists** on patch objects; instead, when a\r\npatch with
Windows-style CRLF line endings is parsed, **the lines in\r\n`lines`
will end with `\\r`**. There is now a **new\r\n`autoConvertLineEndings`
option, on by default**, which makes it so that\r\nwhen a patch with
Windows-style line endings is applied to a source file\r\nwith Unix
style line endings, the patch gets autoconverted to use\r\nUnix-style
line endings, and when a patch with Unix-style line endings\r\nis
applied to a source file with Windows-style line endings, it
gets\r\nautoconverted to use Windows-style line endings.\r\n\r\n-
[#&#8203;521](https://togithub.com/kpdecker/jsdiff/pull/521)
**the\r\n`callback` option is now supported by `structuredPatch`,
`createPatch`,\r\nand `createTwoFilesPatch`**\r\n\r\n-
[#&#8203;529](https://togithub.com/kpdecker/jsdiff/pull/529)\r\n**`parsePatch`
can now parse patches where lines starting with `--` or\r\n`++` are
deleted/inserted**; previously, there were edge cases where
the\r\nparser would choke on valid patches or give wrong
results.\r\n\r\n-
[#&#8203;530](https://togithub.com/kpdecker/jsdiff/pull/530)
**Added\r\n`ignoreNewlineAtEof` option to `diffLines`**\r\n\r\n-
[#&#8203;533](https://togithub.com/kpdecker/jsdiff/pull/533)\r\n**`applyPatch`
uses an entirely new algorithm for fuzzy matching.**\r\nDifferences
between the old and new algorithm are as follows:\r\n- The `fuzzFactor`
now indicates the maximum
[*Levenshtein*\r\ndistance](https://en.wikipedia.org/wiki/Levenshtein_distance)
that there\r\ncan be between the context shown in a hunk and the actual
file content\r\nat a location where we try to apply the hunk.
(Previously, it\r\nrepresented a maximum
[*Hamming*\r\ndistance](https://en.wikipedia.org/wiki/Hamming_distance),
meaning that\r\na single insertion or deletion in the source file could
stop a hunk from\r\napplying even with a high `fuzzFactor`.)\r\n- A hunk
containing a deletion can now only be applied in a context\r\nwhere the
line to be deleted actually appears verbatim. (Previously, as\r\nlong as
enough context lines in the hunk matched, `applyPatch` would\r\napply
the hunk anyway and delete a completely different line.)\r\n- The
context line immediately before and immediately after an
insertion\r\nmust match exactly between the hunk and the file for a hunk
to apply.\r\n(Previously this was not required.)\r\n\r\n-
[#&#8203;535](https://togithub.com/kpdecker/jsdiff/pull/535) **A
bug\r\nin patch generation functions is now fixed** that would
sometimes\r\npreviously cause `\\ No newline at end of file` to appear
in the wrong\r\nplace in the generated patch, resulting in the patch
being invalid.\r\n\r\n-
[#&#8203;535](https://togithub.com/kpdecker/jsdiff/pull/535)
**Passing\r\n`newlineIsToken: true` to *patch*-generation functions is
no longer\r\nallowed.** (Passing it to `diffLines` is still supported -
it's only\r\nfunctions like `createPatch` where passing `newlineIsToken`
is now an\r\nerror.) Allowing it to be passed never really made sense,
since in cases\r\nwhere the option had any effect on the output at all,
the effect tended\r\nto be causing a garbled patch to be created that
couldn't actually be\r\napplied to the source file.\r\n\r\n-
[#&#8203;539](https://togithub.com/kpdecker/jsdiff/pull/539)\r\n**`diffWords`
now takes an optional `intlSegmenter` option** which\r\nshould be an
`Intl.Segmenter` with word-level granularity. This provides\r\nbetter
tokenization of text into words than the default behaviour, even\r\nfor
English but especially for some other languages for which the\r\ndefault
behaviour is
poor.\r\n\r\n###\r\n[`v5.2.0`](https://togithub.com/kpdecker/jsdiff/blob/HEAD/release-notes.md#v520)\r\n\r\n[Compare\r\nSource](https://togithub.com/kpdecker/jsdiff/compare/v5.1.0...v5.2.0)\r\n\r\n[Commits](https://togithub.com/kpdecker/jsdiff/compare/v5.1.0...v5.2.0)\r\n\r\n-
[#&#8203;411](https://togithub.com/kpdecker/jsdiff/pull/411)
Big\r\nperformance improvement. Previously an O(n) array-copying
operation\r\ninside the innermost loop of jsdiff's base diffing code
increased the\r\noverall worst-case time complexity of computing a diff
from O(n²) to\r\nO(n³). This is now fixed, bringing the worst-case time
complexity down\r\nto what it theoretically should be for a Myers diff
implementation.\r\n-
[#&#8203;448](https://togithub.com/kpdecker/jsdiff/pull/448)\r\nPerformance
improvement. Diagonals whose furthest-reaching D-path would\r\ngo off
the edge of the edit graph are now skipped, rather than
being\r\npointlessly considered as called for by the original Myers
diff\r\nalgorithm. This dramatically speeds up computing diffs where the
new\r\ntext just appends or truncates content at the end of the old
text.\r\n-
[#&#8203;351](https://togithub.com/kpdecker/jsdiff/issues/351)\r\nImporting
from the lib folder - e.g. `require(\"diff/lib/diff/word.js\")`\r\n-
will work again now. This had been broken for users on the
latest\r\nversion of Node since Node 17.5.0, which changed how Node
interprets the\r\n`exports` property in jsdiff's `package.json`
file.\r\n-
[#&#8203;344](https://togithub.com/kpdecker/jsdiff/issues/344)\r\n`diffLines`,
`createTwoFilesPatch`, and other patch-creation methods now\r\ntake an
optional `stripTrailingCr: true` option which causes\r\nWindows-style
`\\r\\n` line endings to be replaced with Unix-style `\\n`\r\nline
endings before calculating the diff, just like GNU
`diff`'s\r\n`--strip-trailing-cr` flag.\r\n-
[#&#8203;451](https://togithub.com/kpdecker/jsdiff/pull/451)
Added\r\n`diff.formatPatch`.\r\n-
[#&#8203;450](https://togithub.com/kpdecker/jsdiff/pull/450)
Added\r\n`diff.reversePatch`.\r\n-
[#&#8203;478](https://togithub.com/kpdecker/jsdiff/pull/478)
Added\r\n`timeout`
option.\r\n\r\n</details>\r\n\r\n<details>\r\n<summary>ka-weihe/fastest-levenshtein
(fastest-levenshtein)</summary>\r\n\r\n###\r\n[`v1.0.16`](https://togithub.com/ka-weihe/fastest-levenshtein/compare/1.0.15...03d621ba324d0f665b3b7f557429ca622560d9a3)\r\n\r\n[Compare\r\nSource](https://togithub.com/ka-weihe/fastest-levenshtein/compare/1.0.15...03d621ba324d0f665b3b7f557429ca622560d9a3)\r\n\r\n###\r\n[`v1.0.15`](https://togithub.com/ka-weihe/fastest-levenshtein/compare/37bd0917de8347c73d67467bd1c5ea803cba5f94...1.0.15)\r\n\r\n[Compare\r\nSource](https://togithub.com/ka-weihe/fastest-levenshtein/compare/37bd0917de8347c73d67467bd1c5ea803cba5f94...1.0.15)\r\n\r\n###\r\n[`v1.0.14`](https://togithub.com/ka-weihe/fastest-levenshtein/compare/45d58d245e0d75138bb7da00dd1188ef8d6fdb84...37bd0917de8347c73d67467bd1c5ea803cba5f94)\r\n\r\n[Compare\r\nSource](https://togithub.com/ka-weihe/fastest-levenshtein/compare/45d58d245e0d75138bb7da00dd1188ef8d6fdb84...37bd0917de8347c73d67467bd1c5ea803cba5f94)\r\n\r\n###\r\n[`v1.0.13`](https://togithub.com/ka-weihe/fastest-levenshtein/compare/606c132c58039c22989fa0d2d91d4e2d8bbb2404...45d58d245e0d75138bb7da00dd1188ef8d6fdb84)\r\n\r\n[Compare\r\nSource](https://togithub.com/ka-weihe/fastest-levenshtein/compare/606c132c58039c22989fa0d2d91d4e2d8bbb2404...45d58d245e0d75138bb7da00dd1188ef8d6fdb84)\r\n\r\n</details>\r\n\r\n---\r\n\r\n###
Configuration\r\n\r\n📅 **Schedule**: Branch creation - At any time (no
schedule defined),\r\nAutomerge - At any time (no schedule
defined).\r\n\r\n🚦 **Automerge**: Disabled by config. Please merge this
manually once you\r\nare satisfied.\r\n\r\n♻ **Rebasing**: Whenever PR
becomes conflicted, or you tick the\r\nrebase/retry checkbox.\r\n\r\n👻
**Immortal**: This PR will be recreated if closed unmerged.
Get\r\n[config
help](https://togithub.com/renovatebot/renovate/discussions)
if\r\nthat's undesired.\r\n\r\n---\r\n\r\n- [ ] <!-- rebase-check -->If
you want to rebase/retry this PR, check\r\nthis
box\r\n\r\n---\r\n\r\nThis PR has been generated by
[Renovate\r\nBot](https://togithub.com/renovatebot/renovate).\r\n\r\n<!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiIzNy40MjUuMSIsInVwZGF0ZWRJblZlciI6IjM3LjQyNS4xIiwidGFyZ2V0QnJhbmNoIjoibWFpbiIsImxhYmVscyI6WyJUZWFtOkRhdGFEaXNjb3ZlcnkiLCJiYWNrcG9ydDphbGwtb3BlbiIsInJlbGVhc2Vfbm90ZTpza2lwIl19-->\r\n\r\n---------\r\n\r\nCo-authored-by:
elastic-renovate-prod[bot]
<174716857+elastic-renovate-prod[bot]@users.noreply.github.com>\r\nCo-authored-by:
kibanamachine
<42973632+kibanamachine@users.noreply.github.com>\r\nCo-authored-by:
Davis McPhee <davis.mcphee@elastic.co>\r\nCo-authored-by: Nikita Indik
<nikita.indik@elastic.co>\r\nCo-authored-by: Matthias Wilhelm
<matthias.wilhelm@elastic.co>","sha":"90e738f09d586e96ccad8a257e40c7b3beb36674","branchLabelMapping":{"^v9.0.0$":"main","^v8.18.0$":"8.x","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["release_note:skip","v9.0.0","Team:DataDiscovery","backport:prev-minor"],"title":"Update
@elastic/kibana-data-discovery dependencies
(main)","number":202622,"url":"https://github.com/elastic/kibana/pull/202622","mergeCommit":{"message":"Update
@elastic/kibana-data-discovery dependencies (main) (#202622)\n\nThis PR
contains the following updates:\r\n\r\n| Package | Type | Update |
Change
|\r\n|---|---|---|---|\r\n|\r\n[@types/diff](https://togithub.com/DefinitelyTyped/DefinitelyTyped/tree/master/types/diff)\r\n([source](https://togithub.com/DefinitelyTyped/DefinitelyTyped/tree/HEAD/types/diff))\r\n|
devDependencies | major | [`^5.0.8`
->\r\n`^6.0.0`](https://renovatebot.com/diffs/npm/@types%2fdiff/5.0.8/6.0.0)
|\r\n| [diff](https://togithub.com/kpdecker/jsdiff) | dependencies |
major |\r\n[`^5.1.0`
->\r\n`^7.0.0`](https://renovatebot.com/diffs/npm/diff/5.1.0/7.0.0)
|\r\n|\r\n[fastest-levenshtein](https://togithub.com/ka-weihe/fastest-levenshtein)\r\n|
dependencies | patch | [`^1.0.12`
->\r\n`^1.0.16`](https://renovatebot.com/diffs/npm/fastest-levenshtein/1.0.12/1.0.16)\r\n|\r\n\r\n---\r\n\r\n###
Release Notes\r\n\r\n<details>\r\n<summary>kpdecker/jsdiff
(diff)</summary>\r\n\r\n###\r\n[`v7.0.0`](https://togithub.com/kpdecker/jsdiff/blob/HEAD/release-notes.md#700)\r\n\r\n[Compare\r\nSource](https://togithub.com/kpdecker/jsdiff/compare/v6.0.0...7.0.0)\r\n\r\nJust
a single (breaking) bugfix, undoing a behaviour change
introduced\r\naccidentally in 6.0.0:\r\n\r\n-
[#&#8203;554](https://togithub.com/kpdecker/jsdiff/pull/554)\r\n**`diffWords`
treats numbers and underscores as word characters again.**\r\nThis
behaviour was broken in
v6.0.0.\r\n\r\n###\r\n[`v6.0.0`](https://togithub.com/kpdecker/jsdiff/blob/HEAD/release-notes.md#600)\r\n\r\n[Compare\r\nSource](https://togithub.com/kpdecker/jsdiff/compare/v5.2.0...v6.0.0)\r\n\r\nThis
is a release containing many, *many* breaking changes. The\r\nobjective
of this release was to carry out a mass fix, in one go, of all\r\nthe
open bugs and design problems that required breaking changes to
fix.\r\nA substantial, but exhaustive, changelog is
below.\r\n\r\n[Commits](https://togithub.com/kpdecker/jsdiff/compare/v5.2.0...v6.0.0)\r\n\r\n-
[#&#8203;497](https://togithub.com/kpdecker/jsdiff/pull/497)\r\n**`diffWords`
behavior has been radically changed.** Previously, even\r\nwith
`ignoreWhitespace: true`, runs of whitespace were tokens, which
led\r\nto unhelpful and unintuitive diffing behavior in typical
texts.\r\nSpecifically, even when two texts contained overlapping
passages,\r\n`diffWords` would sometimes choose to delete all the words
from the old\r\ntext and insert them anew in their new positions in
order to avoid\r\nhaving to delete or insert whitespace tokens.
Whitespace sequences are\r\nno longer tokens as of this release, which
affects both the generated\r\ndiffs and the `count`s.\r\n\r\n Runs of
whitespace are still tokens in `diffWordsWithSpace`.\r\n\r\nAs part of
the changes to `diffWords`, **a new `.postProcess` method has\r\nbeen
added on the base `Diff` type**, which can be overridden in
custom\r\n`Diff` implementations.\r\n\r\n**`diffLines` with
`ignoreWhitespace: true` will no longer ignore the\r\ninsertion or
deletion of entire extra lines of whitespace at the end of\r\nthe
text**. Previously, these would not show up as insertions
or\r\ndeletions, as a side effect of a hack in the base diffing
algorithm\r\nmeant to help ignore whitespace in `diffWords`. More
generally, **the\r\nundocumented special handling in the core algorithm
for ignored\r\nterminals has been removed entirely.** (This special case
behavior used\r\nto rewrite the final two change objects in a scenario
where the final\r\nchange object was an addition or deletion and its
`value` was treated as\r\nequal to the empty string when compared using
the diff object's\r\n`.equals` method.)\r\n\r\n-
[#&#8203;500](https://togithub.com/kpdecker/jsdiff/pull/500)\r\n**`diffChars`
now diffs Unicode code points** instead of UTF-16
code\r\nunits.\r\n\r\n-
[#&#8203;508](https://togithub.com/kpdecker/jsdiff/pull/508)\r\n**`parsePatch`
now always runs in what was previously \"strict\" mode;
the\r\nundocumented `strict` option has been removed.** Previously, by
default,\r\n`parsePatch` (and other patch functions that use it under
the hood to\r\nparse patches) would accept a patch where the line counts
in the headers\r\nwere inconsistent with the actual patch content - e.g.
where a hunk\r\nstarted with the header `@@&#8203; -1,3 +1,6
@&#8203;@&#8203;`,\r\nindicating that the content below spanned 3 lines
in the old file and 6\r\nlines in the new file, but then the actual
content below the header\r\nconsisted of some different number of lines,
say 10 lines of context, 5\r\ndeletions, and 1 insertion. Actually
trying to work with these patches\r\nusing `applyPatch` or `merge`,
however, would produce incorrect results\r\ninstead of just ignoring the
incorrect headers, making this \"feature\"\r\nmore of a trap than
something actually useful. It's been ripped out, and\r\nnow we are
always \"strict\" and will reject patches where the line counts\r\nin
the headers aren't consistent with the actual patch content.\r\n\r\n-
[#&#8203;435](https://togithub.com/kpdecker/jsdiff/pull/435)
**Fix\r\n`parsePatch` handling of control characters.** `parsePatch`
used to\r\ninterpret various unusual control characters - namely
vertical tabs,\r\nform feeds, lone carriage returns without a line feed,
and EBCDIC NELs -\r\nas line breaks when parsing a patch file. This was
inconsistent with the\r\nbehavior of both JsDiff's own `diffLines`
method and also the Unix\r\n`diff` and `patch` utils, which all simply
treat those control\r\ncharacters as ordinary characters. The result of
this discrepancy was\r\nthat some well-formed patches - produced either
by `diff` or by JsDiff\r\nitself and handled properly by the `patch`
util - would be wrongly\r\nparsed by `parsePatch`, with the effect that
it would disregard the\r\nremainder of a hunk after encountering one of
these control characters.\r\n\r\n-
[#&#8203;439](https://togithub.com/kpdecker/jsdiff/pull/439)
**Prefer\r\ndiffs that order deletions before insertions.** When faced
with a choice\r\nbetween two diffs with an equal total edit distance,
the Myers diff\r\nalgorithm generally prefers one that does deletions
before insertions\r\nrather than insertions before deletions. For
instance, when diffing\r\n`abcd` against `acbd`, it will prefer a diff
that says to delete the `b`\r\nand then insert a new `b` after the `c`,
over a diff that says to insert\r\na `c` before the `b` and then delete
the existing `c`. JsDiff deviated\r\nfrom the published Myers algorithm
in a way that led to it having the\r\nopposite preference in many cases,
including that example. This is now\r\nfixed, meaning diffs output by
JsDiff will more accurately reflect what\r\nthe published Myers diff
algorithm would output.\r\n\r\n-
[#&#8203;455](https://togithub.com/kpdecker/jsdiff/pull/455)
**The\r\n`added` and `removed` properties of change objects are now
guaranteed to\r\nbe set to a boolean value.** (Previously, they would be
set to\r\n`undefined` or omitted entirely instead of setting them to
false.)\r\n\r\n-
[#&#8203;464](https://togithub.com/kpdecker/jsdiff/pull/464)\r\nSpecifying
`{maxEditLength: 0}` now sets a max edit length of 0 instead\r\nof no
maximum.\r\n\r\n-
[#&#8203;460](https://togithub.com/kpdecker/jsdiff/pull/460)
**Added\r\n`oneChangePerToken` option.**\r\n\r\n-
[#&#8203;467](https://togithub.com/kpdecker/jsdiff/pull/467)\r\n**Consistent
ordering of arguments to `comparator(left, right)`.**\r\nValues from the
old array will now consistently be passed as the first\r\nargument
(`left`) and values from the new array as the second
argument\r\n(`right`). Previously this was almost (but not quite) always
the other\r\nway round.\r\n\r\n-
[#&#8203;480](https://togithub.com/kpdecker/jsdiff/pull/480)
**Passing\r\n`maxEditLength` to `createPatch` & `createTwoFilesPatch`
now works\r\nproperly** (i.e. returns undefined if the max edit distance
is exceeded;\r\nprevious behavior was to crash with a `TypeError` if the
edit distance\r\nwas exceeded).\r\n\r\n-
[#&#8203;486](https://togithub.com/kpdecker/jsdiff/pull/486)
**The\r\n`ignoreWhitespace` option of `diffLines` behaves more sensibly
now.**\r\n`value`s in returned change objects now include
leading/trailing\r\nwhitespace even when `ignoreWhitespace` is used,
just like how with\r\n`ignoreCase` the `value`s still reflect the case
of one of the original\r\ntexts instead of being all-lowercase.
`ignoreWhitespace` is also now\r\ncompatible with `newlineIsToken`.
Finally, **`diffTrimmedLines` is\r\ndeprecated** (and removed from the
docs) in favour of using `diffLines`\r\nwith `ignoreWhitespace: true`;
the two are, and always have been,\r\nequivalent.\r\n\r\n-
[#&#8203;490](https://togithub.com/kpdecker/jsdiff/pull/490)
**When\r\ncalling diffing functions in async mode by passing a
`callback` option,\r\nthe diff result will now be passed as the *first*
argument to the\r\ncallback instead of the second.** (Previously, the
first argument was\r\nnever used at all and would always have value
`undefined`.)\r\n\r\n-
[#&#8203;489](togithub.com/kpdecker/jsdiff/pull/489)
**`this.options`\r\nno longer exists on `Diff` objects.** Instead,
`options` is now passed\r\nas an argument to methods that rely on
options, like `equals(left,\r\nright, options)`. This fixes a race
condition in async mode, where\r\ndiffing behaviour could be changed
mid-execution if a concurrent usage\r\nof the same `Diff` instances
overwrote its `options`.\r\n\r\n-
[#&#8203;518](https://togithub.com/kpdecker/jsdiff/pull/518)\r\n**`linedelimiters`
no longer exists** on patch objects; instead, when a\r\npatch with
Windows-style CRLF line endings is parsed, **the lines in\r\n`lines`
will end with `\\r`**. There is now a **new\r\n`autoConvertLineEndings`
option, on by default**, which makes it so that\r\nwhen a patch with
Windows-style line endings is applied to a source file\r\nwith Unix
style line endings, the patch gets autoconverted to use\r\nUnix-style
line endings, and when a patch with Unix-style line endings\r\nis
applied to a source file with Windows-style line endings, it
gets\r\nautoconverted to use Windows-style line endings.\r\n\r\n-
[#&#8203;521](https://togithub.com/kpdecker/jsdiff/pull/521)
**the\r\n`callback` option is now supported by `structuredPatch`,
`createPatch`,\r\nand `createTwoFilesPatch`**\r\n\r\n-
[#&#8203;529](https://togithub.com/kpdecker/jsdiff/pull/529)\r\n**`parsePatch`
can now parse patches where lines starting with `--` or\r\n`++` are
deleted/inserted**; previously, there were edge cases where
the\r\nparser would choke on valid patches or give wrong
results.\r\n\r\n-
[#&#8203;530](https://togithub.com/kpdecker/jsdiff/pull/530)
**Added\r\n`ignoreNewlineAtEof` option to `diffLines`**\r\n\r\n-
[#&#8203;533](https://togithub.com/kpdecker/jsdiff/pull/533)\r\n**`applyPatch`
uses an entirely new algorithm for fuzzy matching.**\r\nDifferences
between the old and new algorithm are as follows:\r\n- The `fuzzFactor`
now indicates the maximum
[*Levenshtein*\r\ndistance](https://en.wikipedia.org/wiki/Levenshtein_distance)
that there\r\ncan be between the context shown in a hunk and the actual
file content\r\nat a location where we try to apply the hunk.
(Previously, it\r\nrepresented a maximum
[*Hamming*\r\ndistance](https://en.wikipedia.org/wiki/Hamming_distance),
meaning that\r\na single insertion or deletion in the source file could
stop a hunk from\r\napplying even with a high `fuzzFactor`.)\r\n- A hunk
containing a deletion can now only be applied in a context\r\nwhere the
line to be deleted actually appears verbatim. (Previously, as\r\nlong as
enough context lines in the hunk matched, `applyPatch` would\r\napply
the hunk anyway and delete a completely different line.)\r\n- The
context line immediately before and immediately after an
insertion\r\nmust match exactly between the hunk and the file for a hunk
to apply.\r\n(Previously this was not required.)\r\n\r\n-
[#&#8203;535](https://togithub.com/kpdecker/jsdiff/pull/535) **A
bug\r\nin patch generation functions is now fixed** that would
sometimes\r\npreviously cause `\\ No newline at end of file` to appear
in the wrong\r\nplace in the generated patch, resulting in the patch
being invalid.\r\n\r\n-
[#&#8203;535](https://togithub.com/kpdecker/jsdiff/pull/535)
**Passing\r\n`newlineIsToken: true` to *patch*-generation functions is
no longer\r\nallowed.** (Passing it to `diffLines` is still supported -
it's only\r\nfunctions like `createPatch` where passing `newlineIsToken`
is now an\r\nerror.) Allowing it to be passed never really made sense,
since in cases\r\nwhere the option had any effect on the output at all,
the effect tended\r\nto be causing a garbled patch to be created that
couldn't actually be\r\napplied to the source file.\r\n\r\n-
[#&#8203;539](https://togithub.com/kpdecker/jsdiff/pull/539)\r\n**`diffWords`
now takes an optional `intlSegmenter` option** which\r\nshould be an
`Intl.Segmenter` with word-level granularity. This provides\r\nbetter
tokenization of text into words than the default behaviour, even\r\nfor
English but especially for some other languages for which the\r\ndefault
behaviour is
poor.\r\n\r\n###\r\n[`v5.2.0`](https://togithub.com/kpdecker/jsdiff/blob/HEAD/release-notes.md#v520)\r\n\r\n[Compare\r\nSource](https://togithub.com/kpdecker/jsdiff/compare/v5.1.0...v5.2.0)\r\n\r\n[Commits](https://togithub.com/kpdecker/jsdiff/compare/v5.1.0...v5.2.0)\r\n\r\n-
[#&#8203;411](https://togithub.com/kpdecker/jsdiff/pull/411)
Big\r\nperformance improvement. Previously an O(n) array-copying
operation\r\ninside the innermost loop of jsdiff's base diffing code
increased the\r\noverall worst-case time complexity of computing a diff
from O(n²) to\r\nO(n³). This is now fixed, bringing the worst-case time
complexity down\r\nto what it theoretically should be for a Myers diff
implementation.\r\n-
[#&#8203;448](https://togithub.com/kpdecker/jsdiff/pull/448)\r\nPerformance
improvement. Diagonals whose furthest-reaching D-path would\r\ngo off
the edge of the edit graph are now skipped, rather than
being\r\npointlessly considered as called for by the original Myers
diff\r\nalgorithm. This dramatically speeds up computing diffs where the
new\r\ntext just appends or truncates content at the end of the old
text.\r\n-
[#&#8203;351](https://togithub.com/kpdecker/jsdiff/issues/351)\r\nImporting
from the lib folder - e.g. `require(\"diff/lib/diff/word.js\")`\r\n-
will work again now. This had been broken for users on the
latest\r\nversion of Node since Node 17.5.0, which changed how Node
interprets the\r\n`exports` property in jsdiff's `package.json`
file.\r\n-
[#&#8203;344](https://togithub.com/kpdecker/jsdiff/issues/344)\r\n`diffLines`,
`createTwoFilesPatch`, and other patch-creation methods now\r\ntake an
optional `stripTrailingCr: true` option which causes\r\nWindows-style
`\\r\\n` line endings to be replaced with Unix-style `\\n`\r\nline
endings before calculating the diff, just like GNU
`diff`'s\r\n`--strip-trailing-cr` flag.\r\n-
[#&#8203;451](https://togithub.com/kpdecker/jsdiff/pull/451)
Added\r\n`diff.formatPatch`.\r\n-
[#&#8203;450](https://togithub.com/kpdecker/jsdiff/pull/450)
Added\r\n`diff.reversePatch`.\r\n-
[#&#8203;478](https://togithub.com/kpdecker/jsdiff/pull/478)
Added\r\n`timeout`
option.\r\n\r\n</details>\r\n\r\n<details>\r\n<summary>ka-weihe/fastest-levenshtein
(fastest-levenshtein)</summary>\r\n\r\n###\r\n[`v1.0.16`](https://togithub.com/ka-weihe/fastest-levenshtein/compare/1.0.15...03d621ba324d0f665b3b7f557429ca622560d9a3)\r\n\r\n[Compare\r\nSource](https://togithub.com/ka-weihe/fastest-levenshtein/compare/1.0.15...03d621ba324d0f665b3b7f557429ca622560d9a3)\r\n\r\n###\r\n[`v1.0.15`](https://togithub.com/ka-weihe/fastest-levenshtein/compare/37bd0917de8347c73d67467bd1c5ea803cba5f94...1.0.15)\r\n\r\n[Compare\r\nSource](https://togithub.com/ka-weihe/fastest-levenshtein/compare/37bd0917de8347c73d67467bd1c5ea803cba5f94...1.0.15)\r\n\r\n###\r\n[`v1.0.14`](https://togithub.com/ka-weihe/fastest-levenshtein/compare/45d58d245e0d75138bb7da00dd1188ef8d6fdb84...37bd0917de8347c73d67467bd1c5ea803cba5f94)\r\n\r\n[Compare\r\nSource](https://togithub.com/ka-weihe/fastest-levenshtein/compare/45d58d245e0d75138bb7da00dd1188ef8d6fdb84...37bd0917de8347c73d67467bd1c5ea803cba5f94)\r\n\r\n###\r\n[`v1.0.13`](https://togithub.com/ka-weihe/fastest-levenshtein/compare/606c132c58039c22989fa0d2d91d4e2d8bbb2404...45d58d245e0d75138bb7da00dd1188ef8d6fdb84)\r\n\r\n[Compare\r\nSource](https://togithub.com/ka-weihe/fastest-levenshtein/compare/606c132c58039c22989fa0d2d91d4e2d8bbb2404...45d58d245e0d75138bb7da00dd1188ef8d6fdb84)\r\n\r\n</details>\r\n\r\n---\r\n\r\n###
Configuration\r\n\r\n📅 **Schedule**: Branch creation - At any time (no
schedule defined),\r\nAutomerge - At any time (no schedule
defined).\r\n\r\n🚦 **Automerge**: Disabled by config. Please merge this
manually once you\r\nare satisfied.\r\n\r\n♻ **Rebasing**: Whenever PR
becomes conflicted, or you tick the\r\nrebase/retry checkbox.\r\n\r\n👻
**Immortal**: This PR will be recreated if closed unmerged.
Get\r\n[config
help](https://togithub.com/renovatebot/renovate/discussions)
if\r\nthat's undesired.\r\n\r\n---\r\n\r\n- [ ] <!-- rebase-check -->If
you want to rebase/retry this PR, check\r\nthis
box\r\n\r\n---\r\n\r\nThis PR has been generated by
[Renovate\r\nBot](https://togithub.com/renovatebot/renovate).\r\n\r\n<!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiIzNy40MjUuMSIsInVwZGF0ZWRJblZlciI6IjM3LjQyNS4xIiwidGFyZ2V0QnJhbmNoIjoibWFpbiIsImxhYmVscyI6WyJUZWFtOkRhdGFEaXNjb3ZlcnkiLCJiYWNrcG9ydDphbGwtb3BlbiIsInJlbGVhc2Vfbm90ZTpza2lwIl19-->\r\n\r\n---------\r\n\r\nCo-authored-by:
elastic-renovate-prod[bot]
<174716857+elastic-renovate-prod[bot]@users.noreply.github.com>\r\nCo-authored-by:
kibanamachine
<42973632+kibanamachine@users.noreply.github.com>\r\nCo-authored-by:
Davis McPhee <davis.mcphee@elastic.co>\r\nCo-authored-by: Nikita Indik
<nikita.indik@elastic.co>\r\nCo-authored-by: Matthias Wilhelm
<matthias.wilhelm@elastic.co>","sha":"90e738f09d586e96ccad8a257e40c7b3beb36674"}},"sourceBranch":"main","suggestedTargetBranches":[],"targetPullRequestStates":[{"branch":"main","label":"v9.0.0","branchLabelMappingKey":"^v9.0.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/202622","number":202622,"mergeCommit":{"message":"Update
@elastic/kibana-data-discovery dependencies (main) (#202622)\n\nThis PR
contains the following updates:\r\n\r\n| Package | Type | Update |
Change
|\r\n|---|---|---|---|\r\n|\r\n[@types/diff](https://togithub.com/DefinitelyTyped/DefinitelyTyped/tree/master/types/diff)\r\n([source](https://togithub.com/DefinitelyTyped/DefinitelyTyped/tree/HEAD/types/diff))\r\n|
devDependencies | major | [`^5.0.8`
->\r\n`^6.0.0`](https://renovatebot.com/diffs/npm/@types%2fdiff/5.0.8/6.0.0)
|\r\n| [diff](https://togithub.com/kpdecker/jsdiff) | dependencies |
major |\r\n[`^5.1.0`
->\r\n`^7.0.0`](https://renovatebot.com/diffs/npm/diff/5.1.0/7.0.0)
|\r\n|\r\n[fastest-levenshtein](https://togithub.com/ka-weihe/fastest-levenshtein)\r\n|
dependencies | patch | [`^1.0.12`
->\r\n`^1.0.16`](https://renovatebot.com/diffs/npm/fastest-levenshtein/1.0.12/1.0.16)\r\n|\r\n\r\n---\r\n\r\n###
Release Notes\r\n\r\n<details>\r\n<summary>kpdecker/jsdiff
(diff)</summary>\r\n\r\n###\r\n[`v7.0.0`](https://togithub.com/kpdecker/jsdiff/blob/HEAD/release-notes.md#700)\r\n\r\n[Compare\r\nSource](https://togithub.com/kpdecker/jsdiff/compare/v6.0.0...7.0.0)\r\n\r\nJust
a single (breaking) bugfix, undoing a behaviour change
introduced\r\naccidentally in 6.0.0:\r\n\r\n-
[#&#8203;554](https://togithub.com/kpdecker/jsdiff/pull/554)\r\n**`diffWords`
treats numbers and underscores as word characters again.**\r\nThis
behaviour was broken in
v6.0.0.\r\n\r\n###\r\n[`v6.0.0`](https://togithub.com/kpdecker/jsdiff/blob/HEAD/release-notes.md#600)\r\n\r\n[Compare\r\nSource](https://togithub.com/kpdecker/jsdiff/compare/v5.2.0...v6.0.0)\r\n\r\nThis
is a release containing many, *many* breaking changes. The\r\nobjective
of this release was to carry out a mass fix, in one go, of all\r\nthe
open bugs and design problems that required breaking changes to
fix.\r\nA substantial, but exhaustive, changelog is
below.\r\n\r\n[Commits](https://togithub.com/kpdecker/jsdiff/compare/v5.2.0...v6.0.0)\r\n\r\n-
[#&#8203;497](https://togithub.com/kpdecker/jsdiff/pull/497)\r\n**`diffWords`
behavior has been radically changed.** Previously, even\r\nwith
`ignoreWhitespace: true`, runs of whitespace were tokens, which
led\r\nto unhelpful and unintuitive diffing behavior in typical
texts.\r\nSpecifically, even when two texts contained overlapping
passages,\r\n`diffWords` would sometimes choose to delete all the words
from the old\r\ntext and insert them anew in their new positions in
order to avoid\r\nhaving to delete or insert whitespace tokens.
Whitespace sequences are\r\nno longer tokens as of this release, which
affects both the generated\r\ndiffs and the `count`s.\r\n\r\n Runs of
whitespace are still tokens in `diffWordsWithSpace`.\r\n\r\nAs part of
the changes to `diffWords`, **a new `.postProcess` method has\r\nbeen
added on the base `Diff` type**, which can be overridden in
custom\r\n`Diff` implementations.\r\n\r\n**`diffLines` with
`ignoreWhitespace: true` will no longer ignore the\r\ninsertion or
deletion of entire extra lines of whitespace at the end of\r\nthe
text**. Previously, these would not show up as insertions
or\r\ndeletions, as a side effect of a hack in the base diffing
algorithm\r\nmeant to help ignore whitespace in `diffWords`. More
generally, **the\r\nundocumented special handling in the core algorithm
for ignored\r\nterminals has been removed entirely.** (This special case
behavior used\r\nto rewrite the final two change objects in a scenario
where the final\r\nchange object was an addition or deletion and its
`value` was treated as\r\nequal to the empty string when compared using
the diff object's\r\n`.equals` method.)\r\n\r\n-
[#&#8203;500](https://togithub.com/kpdecker/jsdiff/pull/500)\r\n**`diffChars`
now diffs Unicode code points** instead of UTF-16
code\r\nunits.\r\n\r\n-
[#&#8203;508](https://togithub.com/kpdecker/jsdiff/pull/508)\r\n**`parsePatch`
now always runs in what was previously \"strict\" mode;
the\r\nundocumented `strict` option has been removed.** Previously, by
default,\r\n`parsePatch` (and other patch functions that use it under
the hood to\r\nparse patches) would accept a patch where the line counts
in the headers\r\nwere inconsistent with the actual patch content - e.g.
where a hunk\r\nstarted with the header `@@&#8203; -1,3 +1,6
@&#8203;@&#8203;`,\r\nindicating that the content below spanned 3 lines
in the old file and 6\r\nlines in the new file, but then the actual
content below the header\r\nconsisted of some different number of lines,
say 10 lines of context, 5\r\ndeletions, and 1 insertion. Actually
trying to work with these patches\r\nusing `applyPatch` or `merge`,
however, would produce incorrect results\r\ninstead of just ignoring the
incorrect headers, making this \"feature\"\r\nmore of a trap than
something actually useful. It's been ripped out, and\r\nnow we are
always \"strict\" and will reject patches where the line counts\r\nin
the headers aren't consistent with the actual patch content.\r\n\r\n-
[#&#8203;435](https://togithub.com/kpdecker/jsdiff/pull/435)
**Fix\r\n`parsePatch` handling of control characters.** `parsePatch`
used to\r\ninterpret various unusual control characters - namely
vertical tabs,\r\nform feeds, lone carriage returns without a line feed,
and EBCDIC NELs -\r\nas line breaks when parsing a patch file. This was
inconsistent with the\r\nbehavior of both JsDiff's own `diffLines`
method and also the Unix\r\n`diff` and `patch` utils, which all simply
treat those control\r\ncharacters as ordinary characters. The result of
this discrepancy was\r\nthat some well-formed patches - produced either
by `diff` or by JsDiff\r\nitself and handled properly by the `patch`
util - would be wrongly\r\nparsed by `parsePatch`, with the effect that
it would disregard the\r\nremainder of a hunk after encountering one of
these control characters.\r\n\r\n-
[#&#8203;439](https://togithub.com/kpdecker/jsdiff/pull/439)
**Prefer\r\ndiffs that order deletions before insertions.** When faced
with a choice\r\nbetween two diffs with an equal total edit distance,
the Myers diff\r\nalgorithm generally prefers one that does deletions
before insertions\r\nrather than insertions before deletions. For
instance, when diffing\r\n`abcd` against `acbd`, it will prefer a diff
that says to delete the `b`\r\nand then insert a new `b` after the `c`,
over a diff that says to insert\r\na `c` before the `b` and then delete
the existing `c`. JsDiff deviated\r\nfrom the published Myers algorithm
in a way that led to it having the\r\nopposite preference in many cases,
including that example. This is now\r\nfixed, meaning diffs output by
JsDiff will more accurately reflect what\r\nthe published Myers diff
algorithm would output.\r\n\r\n-
[#&#8203;455](https://togithub.com/kpdecker/jsdiff/pull/455)
**The\r\n`added` and `removed` properties of change objects are now
guaranteed to\r\nbe set to a boolean value.** (Previously, they would be
set to\r\n`undefined` or omitted entirely instead of setting them to
false.)\r\n\r\n-
[#&#8203;464](https://togithub.com/kpdecker/jsdiff/pull/464)\r\nSpecifying
`{maxEditLength: 0}` now sets a max edit length of 0 instead\r\nof no
maximum.\r\n\r\n-
[#&#8203;460](https://togithub.com/kpdecker/jsdiff/pull/460)
**Added\r\n`oneChangePerToken` option.**\r\n\r\n-
[#&#8203;467](https://togithub.com/kpdecker/jsdiff/pull/467)\r\n**Consistent
ordering of arguments to `comparator(left, right)`.**\r\nValues from the
old array will now consistently be passed as the first\r\nargument
(`left`) and values from the new array as the second
argument\r\n(`right`). Previously this was almost (but not quite) always
the other\r\nway round.\r\n\r\n-
[#&#8203;480](https://togithub.com/kpdecker/jsdiff/pull/480)
**Passing\r\n`maxEditLength` to `createPatch` & `createTwoFilesPatch`
now works\r\nproperly** (i.e. returns undefined if the max edit distance
is exceeded;\r\nprevious behavior was to crash with a `TypeError` if the
edit distance\r\nwas exceeded).\r\n\r\n-
[#&#8203;486](https://togithub.com/kpdecker/jsdiff/pull/486)
**The\r\n`ignoreWhitespace` option of `diffLines` behaves more sensibly
now.**\r\n`value`s in returned change objects now include
leading/trailing\r\nwhitespace even when `ignoreWhitespace` is used,
just like how with\r\n`ignoreCase` the `value`s still reflect the case
of one of the original\r\ntexts instead of being all-lowercase.
`ignoreWhitespace` is also now\r\ncompatible with `newlineIsToken`.
Finally, **`diffTrimmedLines` is\r\ndeprecated** (and removed from the
docs) in favour of using `diffLines`\r\nwith `ignoreWhitespace: true`;
the two are, and always have been,\r\nequivalent.\r\n\r\n-
[#&#8203;490](https://togithub.com/kpdecker/jsdiff/pull/490)
**When\r\ncalling diffing functions in async mode by passing a
`callback` option,\r\nthe diff result will now be passed as the *first*
argument to the\r\ncallback instead of the second.** (Previously, the
first argument was\r\nnever used at all and would always have value
`undefined`.)\r\n\r\n-
[#&#8203;489](togithub.com/kpdecker/jsdiff/pull/489)
**`this.options`\r\nno longer exists on `Diff` objects.** Instead,
`options` is now passed\r\nas an argument to methods that rely on
options, like `equals(left,\r\nright, options)`. This fixes a race
condition in async mode, where\r\ndiffing behaviour could be changed
mid-execution if a concurrent usage\r\nof the same `Diff` instances
overwrote its `options`.\r\n\r\n-
[#&#8203;518](https://togithub.com/kpdecker/jsdiff/pull/518)\r\n**`linedelimiters`
no longer exists** on patch objects; instead, when a\r\npatch with
Windows-style CRLF line endings is parsed, **the lines in\r\n`lines`
will end with `\\r`**. There is now a **new\r\n`autoConvertLineEndings`
option, on by default**, which makes it so that\r\nwhen a patch with
Windows-style line endings is applied to a source file\r\nwith Unix
style line endings, the patch gets autoconverted to use\r\nUnix-style
line endings, and when a patch with Unix-style line endings\r\nis
applied to a source file with Windows-style line endings, it
gets\r\nautoconverted to use Windows-style line endings.\r\n\r\n-
[#&#8203;521](https://togithub.com/kpdecker/jsdiff/pull/521)
**the\r\n`callback` option is now supported by `structuredPatch`,
`createPatch`,\r\nand `createTwoFilesPatch`**\r\n\r\n-
[#&#8203;529](https://togithub.com/kpdecker/jsdiff/pull/529)\r\n**`parsePatch`
can now parse patches where lines starting with `--` or\r\n`++` are
deleted/inserted**; previously, there were edge cases where
the\r\nparser would choke on valid patches or give wrong
results.\r\n\r\n-
[#&#8203;530](https://togithub.com/kpdecker/jsdiff/pull/530)
**Added\r\n`ignoreNewlineAtEof` option to `diffLines`**\r\n\r\n-
[#&#8203;533](https://togithub.com/kpdecker/jsdiff/pull/533)\r\n**`applyPatch`
uses an entirely new algorithm for fuzzy matching.**\r\nDifferences
between the old and new algorithm are as follows:\r\n- The `fuzzFactor`
now indicates the maximum
[*Levenshtein*\r\ndistance](https://en.wikipedia.org/wiki/Levenshtein_distance)
that there\r\ncan be between the context shown in a hunk and the actual
file content\r\nat a location where we try to apply the hunk.
(Previously, it\r\nrepresented a maximum
[*Hamming*\r\ndistance](https://en.wikipedia.org/wiki/Hamming_distance),
meaning that\r\na single insertion or deletion in the source file could
stop a hunk from\r\napplying even with a high `fuzzFactor`.)\r\n- A hunk
containing a deletion can now only be applied in a context\r\nwhere the
line to be deleted actually appears verbatim. (Previously, as\r\nlong as
enough context lines in the hunk matched, `applyPatch` would\r\napply
the hunk anyway and delete a completely different line.)\r\n- The
context line immediately before and immediately after an
insertion\r\nmust match exactly between the hunk and the file for a hunk
to apply.\r\n(Previously this was not required.)\r\n\r\n-
[#&#8203;535](https://togithub.com/kpdecker/jsdiff/pull/535) **A
bug\r\nin patch generation functions is now fixed** that would
sometimes\r\npreviously cause `\\ No newline at end of file` to appear
in the wrong\r\nplace in the generated patch, resulting in the patch
being invalid.\r\n\r\n-
[#&#8203;535](https://togithub.com/kpdecker/jsdiff/pull/535)
**Passing\r\n`newlineIsToken: true` to *patch*-generation functions is
no longer\r\nallowed.** (Passing it to `diffLines` is still supported -
it's only\r\nfunctions like `createPatch` where passing `newlineIsToken`
is now an\r\nerror.) Allowing it to be passed never really made sense,
since in cases\r\nwhere the option had any effect on the output at all,
the effect tended\r\nto be causing a garbled patch to be created that
couldn't actually be\r\napplied to the source file.\r\n\r\n-
[#&#8203;539](https://togithub.com/kpdecker/jsdiff/pull/539)\r\n**`diffWords`
now takes an optional `intlSegmenter` option** which\r\nshould be an
`Intl.Segmenter` with word-level granularity. This provides\r\nbetter
tokenization of text into words than the default behaviour, even\r\nfor
English but especially for some other languages for which the\r\ndefault
behaviour is
poor.\r\n\r\n###\r\n[`v5.2.0`](https://togithub.com/kpdecker/jsdiff/blob/HEAD/release-notes.md#v520)\r\n\r\n[Compare\r\nSource](https://togithub.com/kpdecker/jsdiff/compare/v5.1.0...v5.2.0)\r\n\r\n[Commits](https://togithub.com/kpdecker/jsdiff/compare/v5.1.0...v5.2.0)\r\n\r\n-
[#&#8203;411](https://togithub.com/kpdecker/jsdiff/pull/411)
Big\r\nperformance improvement. Previously an O(n) array-copying
operation\r\ninside the innermost loop of jsdiff's base diffing code
increased the\r\noverall worst-case time complexity of computing a diff
from O(n²) to\r\nO(n³). This is now fixed, bringing the worst-case time
complexity down\r\nto what it theoretically should be for a Myers diff
implementation.\r\n-
[#&#8203;448](https://togithub.com/kpdecker/jsdiff/pull/448)\r\nPerformance
improvement. Diagonals whose furthest-reaching D-path would\r\ngo off
the edge of the edit graph are now skipped, rather than
being\r\npointlessly considered as called for by the original Myers
diff\r\nalgorithm. This dramatically speeds up computing diffs where the
new\r\ntext just appends or truncates content at the end of the old
text.\r\n-
[#&#8203;351](https://togithub.com/kpdecker/jsdiff/issues/351)\r\nImporting
from the lib folder - e.g. `require(\"diff/lib/diff/word.js\")`\r\n-
will work again now. This had been broken for users on the
latest\r\nversion of Node since Node 17.5.0, which changed how Node
interprets the\r\n`exports` property in jsdiff's `package.json`
file.\r\n-
[#&#8203;344](https://togithub.com/kpdecker/jsdiff/issues/344)\r\n`diffLines`,
`createTwoFilesPatch`, and other patch-creation methods now\r\ntake an
optional `stripTrailingCr: true` option which causes\r\nWindows-style
`\\r\\n` line endings to be replaced with Unix-style `\\n`\r\nline
endings before calculating the diff, just like GNU
`diff`'s\r\n`--strip-trailing-cr` flag.\r\n-
[#&#8203;451](https://togithub.com/kpdecker/jsdiff/pull/451)
Added\r\n`diff.formatPatch`.\r\n-
[#&#8203;450](https://togithub.com/kpdecker/jsdiff/pull/450)
Added\r\n`diff.reversePatch`.\r\n-
[#&#8203;478](https://togithub.com/kpdecker/jsdiff/pull/478)
Added\r\n`timeout`
option.\r\n\r\n</details>\r\n\r\n<details>\r\n<summary>ka-weihe/fastest-levenshtein
(fastest-levenshtein)</summary>\r\n\r\n###\r\n[`v1.0.16`](https://togithub.com/ka-weihe/fastest-levenshtein/compare/1.0.15...03d621ba324d0f665b3b7f557429ca622560d9a3)\r\n\r\n[Compare\r\nSource](https://togithub.com/ka-weihe/fastest-levenshtein/compare/1.0.15...03d621ba324d0f665b3b7f557429ca622560d9a3)\r\n\r\n###\r\n[`v1.0.15`](https://togithub.com/ka-weihe/fastest-levenshtein/compare/37bd0917de8347c73d67467bd1c5ea803cba5f94...1.0.15)\r\n\r\n[Compare\r\nSource](https://togithub.com/ka-weihe/fastest-levenshtein/compare/37bd0917de8347c73d67467bd1c5ea803cba5f94...1.0.15)\r\n\r\n###\r\n[`v1.0.14`](https://togithub.com/ka-weihe/fastest-levenshtein/compare/45d58d245e0d75138bb7da00dd1188ef8d6fdb84...37bd0917de8347c73d67467bd1c5ea803cba5f94)\r\n\r\n[Compare\r\nSource](https://togithub.com/ka-weihe/fastest-levenshtein/compare/45d58d245e0d75138bb7da00dd1188ef8d6fdb84...37bd0917de8347c73d67467bd1c5ea803cba5f94)\r\n\r\n###\r\n[`v1.0.13`](https://togithub.com/ka-weihe/fastest-levenshtein/compare/606c132c58039c22989fa0d2d91d4e2d8bbb2404...45d58d245e0d75138bb7da00dd1188ef8d6fdb84)\r\n\r\n[Compare\r\nSource](https://togithub.com/ka-weihe/fastest-levenshtein/compare/606c132c58039c22989fa0d2d91d4e2d8bbb2404...45d58d245e0d75138bb7da00dd1188ef8d6fdb84)\r\n\r\n</details>\r\n\r\n---\r\n\r\n###
Configuration\r\n\r\n📅 **Schedule**: Branch creation - At any time (no
schedule defined),\r\nAutomerge - At any time (no schedule
defined).\r\n\r\n🚦 **Automerge**: Disabled by config. Please merge this
manually once you\r\nare satisfied.\r\n\r\n♻ **Rebasing**: Whenever PR
becomes conflicted, or you tick the\r\nrebase/retry checkbox.\r\n\r\n👻
**Immortal**: This PR will be recreated if closed unmerged.
Get\r\n[config
help](https://togithub.com/renovatebot/renovate/discussions)
if\r\nthat's undesired.\r\n\r\n---\r\n\r\n- [ ] <!-- rebase-check -->If
you want to rebase/retry this PR, check\r\nthis
box\r\n\r\n---\r\n\r\nThis PR has been generated by
[Renovate\r\nBot](https://togithub.com/renovatebot/renovate).\r\n\r\n<!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiIzNy40MjUuMSIsInVwZGF0ZWRJblZlciI6IjM3LjQyNS4xIiwidGFyZ2V0QnJhbmNoIjoibWFpbiIsImxhYmVscyI6WyJUZWFtOkRhdGFEaXNjb3ZlcnkiLCJiYWNrcG9ydDphbGwtb3BlbiIsInJlbGVhc2Vfbm90ZTpza2lwIl19-->\r\n\r\n---------\r\n\r\nCo-authored-by:
elastic-renovate-prod[bot]
<174716857+elastic-renovate-prod[bot]@users.noreply.github.com>\r\nCo-authored-by:
kibanamachine
<42973632+kibanamachine@users.noreply.github.com>\r\nCo-authored-by:
Davis McPhee <davis.mcphee@elastic.co>\r\nCo-authored-by: Nikita Indik
<nikita.indik@elastic.co>\r\nCo-authored-by: Matthias Wilhelm
<matthias.wilhelm@elastic.co>","sha":"90e738f09d586e96ccad8a257e40c7b3beb36674"}}]}]
BACKPORT-->

Co-authored-by: elastic-renovate-prod[bot] <174716857+elastic-renovate-prod[bot]@users.noreply.github.com>
Co-authored-by: Davis McPhee <davis.mcphee@elastic.co>
kowalczyk-krzysztof pushed a commit to kowalczyk-krzysztof/kibana that referenced this pull request Jan 7, 2025
…2622)

This PR contains the following updates:

| Package | Type | Update | Change |
|---|---|---|---|
|
[@types/diff](https://togithub.com/DefinitelyTyped/DefinitelyTyped/tree/master/types/diff)
([source](https://togithub.com/DefinitelyTyped/DefinitelyTyped/tree/HEAD/types/diff))
| devDependencies | major | [`^5.0.8` ->
`^6.0.0`](https://renovatebot.com/diffs/npm/@types%2fdiff/5.0.8/6.0.0) |
| [diff](https://togithub.com/kpdecker/jsdiff) | dependencies | major |
[`^5.1.0` ->
`^7.0.0`](https://renovatebot.com/diffs/npm/diff/5.1.0/7.0.0) |
|
[fastest-levenshtein](https://togithub.com/ka-weihe/fastest-levenshtein)
| dependencies | patch | [`^1.0.12` ->
`^1.0.16`](https://renovatebot.com/diffs/npm/fastest-levenshtein/1.0.12/1.0.16)
|

---

### Release Notes

<details>
<summary>kpdecker/jsdiff (diff)</summary>

###
[`v7.0.0`](https://togithub.com/kpdecker/jsdiff/blob/HEAD/release-notes.md#700)

[Compare
Source](https://togithub.com/kpdecker/jsdiff/compare/v6.0.0...7.0.0)

Just a single (breaking) bugfix, undoing a behaviour change introduced
accidentally in 6.0.0:

- [#&elastic#8203;554](https://togithub.com/kpdecker/jsdiff/pull/554)
**`diffWords` treats numbers and underscores as word characters again.**
This behaviour was broken in v6.0.0.

###
[`v6.0.0`](https://togithub.com/kpdecker/jsdiff/blob/HEAD/release-notes.md#600)

[Compare
Source](https://togithub.com/kpdecker/jsdiff/compare/v5.2.0...v6.0.0)

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.

[Commits](https://togithub.com/kpdecker/jsdiff/compare/v5.2.0...v6.0.0)

- [#&elastic#8203;497](https://togithub.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.

    Runs of whitespace are still tokens in `diffWordsWithSpace`.

As part of the changes to `diffWords`, **a new `.postProcess` method has
been added on the base `Diff` type**, which can be overridden in custom
`Diff` implementations.

**`diffLines` with `ignoreWhitespace: true` will no longer ignore the
insertion or deletion of entire extra lines of whitespace at the end of
the text**. Previously, these would not show up as insertions or
deletions, as a side effect of a hack in the base diffing algorithm
meant to help ignore whitespace in `diffWords`. More generally, **the
undocumented special handling in the core algorithm for ignored
terminals has been removed entirely.** (This special case behavior used
to rewrite the final two change objects in a scenario where the final
change object was an addition or deletion and its `value` was treated as
equal to the empty string when compared using the diff object's
`.equals` method.)

- [#&elastic#8203;500](https://togithub.com/kpdecker/jsdiff/pull/500)
**`diffChars` now diffs Unicode code points** instead of UTF-16 code
units.

- [#&elastic#8203;508](https://togithub.com/kpdecker/jsdiff/pull/508)
**`parsePatch` now always runs in what was previously "strict" mode; the
undocumented `strict` option has been removed.** Previously, by default,
`parsePatch` (and other patch functions that use it under the hood to
parse patches) would accept a patch where the line counts in the headers
were inconsistent with the actual patch content - e.g. where a hunk
started with the header `@@&elastic#8203; -1,3 +1,6 @&elastic#8203;@&elastic#8203;`,
indicating that the content below spanned 3 lines in the old file and 6
lines in the new file, but then the actual content below the header
consisted of some different number of lines, say 10 lines of context, 5
deletions, and 1 insertion. Actually trying to work with these patches
using `applyPatch` or `merge`, however, would produce incorrect results
instead of just ignoring the incorrect headers, making this "feature"
more of a trap than something actually useful. It's been ripped out, and
now we are always "strict" and will reject patches where the line counts
in the headers aren't consistent with the actual patch content.

- [#&elastic#8203;435](https://togithub.com/kpdecker/jsdiff/pull/435) **Fix
`parsePatch` handling of control characters.** `parsePatch` used to
interpret various unusual control characters - namely vertical tabs,
form feeds, lone carriage returns without a line feed, and EBCDIC NELs -
as line breaks when parsing a patch file. This was inconsistent with the
behavior of both JsDiff's own `diffLines` method and also the Unix
`diff` and `patch` utils, which all simply treat those control
characters as ordinary characters. The result of this discrepancy was
that some well-formed patches - produced either by `diff` or by JsDiff
itself and handled properly by the `patch` util - would be wrongly
parsed by `parsePatch`, with the effect that it would disregard the
remainder of a hunk after encountering one of these control characters.

- [#&elastic#8203;439](https://togithub.com/kpdecker/jsdiff/pull/439) **Prefer
diffs that order deletions before insertions.** When faced with a choice
between two diffs with an equal total edit distance, the Myers diff
algorithm generally prefers one that does deletions before insertions
rather than insertions before deletions. For instance, when diffing
`abcd` against `acbd`, it will prefer a diff that says to delete the `b`
and then insert a new `b` after the `c`, over a diff that says to insert
a `c` before the `b` and then delete the existing `c`. JsDiff deviated
from the published Myers algorithm in a way that led to it having the
opposite preference in many cases, including that example. This is now
fixed, meaning diffs output by JsDiff will more accurately reflect what
the published Myers diff algorithm would output.

- [#&elastic#8203;455](https://togithub.com/kpdecker/jsdiff/pull/455) **The
`added` and `removed` properties of change objects are now guaranteed to
be set to a boolean value.** (Previously, they would be set to
`undefined` or omitted entirely instead of setting them to false.)

- [#&elastic#8203;464](https://togithub.com/kpdecker/jsdiff/pull/464)
Specifying `{maxEditLength: 0}` now sets a max edit length of 0 instead
of no maximum.

- [#&elastic#8203;460](https://togithub.com/kpdecker/jsdiff/pull/460) **Added
`oneChangePerToken` option.**

- [#&elastic#8203;467](https://togithub.com/kpdecker/jsdiff/pull/467)
**Consistent ordering of arguments to `comparator(left, right)`.**
Values from the old array will now consistently be passed as the first
argument (`left`) and values from the new array as the second argument
(`right`). Previously this was almost (but not quite) always the other
way round.

- [#&elastic#8203;480](https://togithub.com/kpdecker/jsdiff/pull/480) **Passing
`maxEditLength` to `createPatch` & `createTwoFilesPatch` now works
properly** (i.e. returns undefined if the max edit distance is exceeded;
previous behavior was to crash with a `TypeError` if the edit distance
was exceeded).

- [#&elastic#8203;486](https://togithub.com/kpdecker/jsdiff/pull/486) **The
`ignoreWhitespace` option of `diffLines` behaves more sensibly now.**
`value`s in returned change objects now include leading/trailing
whitespace even when `ignoreWhitespace` is used, just like how with
`ignoreCase` the `value`s still reflect the case of one of the original
texts instead of being all-lowercase. `ignoreWhitespace` is also now
compatible with `newlineIsToken`. Finally, **`diffTrimmedLines` is
deprecated** (and removed from the docs) in favour of using `diffLines`
with `ignoreWhitespace: true`; the two are, and always have been,
equivalent.

- [#&elastic#8203;490](https://togithub.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`.)

- [#&elastic#8203;489](togithub.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`.

- [#&elastic#8203;518](https://togithub.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.

- [#&elastic#8203;521](https://togithub.com/kpdecker/jsdiff/pull/521) **the
`callback` option is now supported by `structuredPatch`, `createPatch`,
and `createTwoFilesPatch`**

- [#&elastic#8203;529](https://togithub.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.

- [#&elastic#8203;530](https://togithub.com/kpdecker/jsdiff/pull/530) **Added
`ignoreNewlineAtEof` option to `diffLines`**

- [#&elastic#8203;533](https://togithub.com/kpdecker/jsdiff/pull/533)
**`applyPatch` uses an entirely new algorithm for fuzzy matching.**
Differences between the old and new algorithm are as follows:
- 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`.)
- 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.)
- The context line immediately before and immediately after an insertion
must match exactly between the hunk and the file for a hunk to apply.
(Previously this was not required.)

- [#&elastic#8203;535](https://togithub.com/kpdecker/jsdiff/pull/535) **A bug
in patch generation functions is now fixed** that would sometimes
previously cause `\ No newline at end of file` to appear in the wrong
place in the generated patch, resulting in the patch being invalid.

- [#&elastic#8203;535](https://togithub.com/kpdecker/jsdiff/pull/535) **Passing
`newlineIsToken: true` to *patch*-generation functions is no longer
allowed.** (Passing it to `diffLines` is still supported - it's only
functions like `createPatch` where passing `newlineIsToken` is now an
error.) Allowing it to be passed never really made sense, since in cases
where the option had any effect on the output at all, the effect tended
to be causing a garbled patch to be created that couldn't actually be
applied to the source file.

- [#&elastic#8203;539](https://togithub.com/kpdecker/jsdiff/pull/539)
**`diffWords` now takes an optional `intlSegmenter` option** which
should be an `Intl.Segmenter` with word-level granularity. This provides
better tokenization of text into words than the default behaviour, even
for English but especially for some other languages for which the
default behaviour is poor.

###
[`v5.2.0`](https://togithub.com/kpdecker/jsdiff/blob/HEAD/release-notes.md#v520)

[Compare
Source](https://togithub.com/kpdecker/jsdiff/compare/v5.1.0...v5.2.0)

[Commits](https://togithub.com/kpdecker/jsdiff/compare/v5.1.0...v5.2.0)

- [#&elastic#8203;411](https://togithub.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.
- [#&elastic#8203;448](https://togithub.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.
- [#&elastic#8203;351](https://togithub.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.
- [#&elastic#8203;344](https://togithub.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.
- [#&elastic#8203;451](https://togithub.com/kpdecker/jsdiff/pull/451) Added
`diff.formatPatch`.
- [#&elastic#8203;450](https://togithub.com/kpdecker/jsdiff/pull/450) Added
`diff.reversePatch`.
- [#&elastic#8203;478](https://togithub.com/kpdecker/jsdiff/pull/478) Added
`timeout` option.

</details>

<details>
<summary>ka-weihe/fastest-levenshtein (fastest-levenshtein)</summary>

###
[`v1.0.16`](https://togithub.com/ka-weihe/fastest-levenshtein/compare/1.0.15...03d621ba324d0f665b3b7f557429ca622560d9a3)

[Compare
Source](https://togithub.com/ka-weihe/fastest-levenshtein/compare/1.0.15...03d621ba324d0f665b3b7f557429ca622560d9a3)

###
[`v1.0.15`](https://togithub.com/ka-weihe/fastest-levenshtein/compare/37bd0917de8347c73d67467bd1c5ea803cba5f94...1.0.15)

[Compare
Source](https://togithub.com/ka-weihe/fastest-levenshtein/compare/37bd0917de8347c73d67467bd1c5ea803cba5f94...1.0.15)

###
[`v1.0.14`](https://togithub.com/ka-weihe/fastest-levenshtein/compare/45d58d245e0d75138bb7da00dd1188ef8d6fdb84...37bd0917de8347c73d67467bd1c5ea803cba5f94)

[Compare
Source](https://togithub.com/ka-weihe/fastest-levenshtein/compare/45d58d245e0d75138bb7da00dd1188ef8d6fdb84...37bd0917de8347c73d67467bd1c5ea803cba5f94)

###
[`v1.0.13`](https://togithub.com/ka-weihe/fastest-levenshtein/compare/606c132c58039c22989fa0d2d91d4e2d8bbb2404...45d58d245e0d75138bb7da00dd1188ef8d6fdb84)

[Compare
Source](https://togithub.com/ka-weihe/fastest-levenshtein/compare/606c132c58039c22989fa0d2d91d4e2d8bbb2404...45d58d245e0d75138bb7da00dd1188ef8d6fdb84)

</details>

---

### Configuration

📅 **Schedule**: Branch creation - At any time (no schedule defined),
Automerge - At any time (no schedule defined).

🚦 **Automerge**: Disabled by config. Please merge this manually once you
are satisfied.

♻ **Rebasing**: Whenever PR becomes conflicted, or you tick the
rebase/retry checkbox.

👻 **Immortal**: This PR will be recreated if closed unmerged. Get
[config help](https://togithub.com/renovatebot/renovate/discussions) if
that's undesired.

---

- [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check
this box

---

This PR has been generated by [Renovate
Bot](https://togithub.com/renovatebot/renovate).

<!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiIzNy40MjUuMSIsInVwZGF0ZWRJblZlciI6IjM3LjQyNS4xIiwidGFyZ2V0QnJhbmNoIjoibWFpbiIsImxhYmVscyI6WyJUZWFtOkRhdGFEaXNjb3ZlcnkiLCJiYWNrcG9ydDphbGwtb3BlbiIsInJlbGVhc2Vfbm90ZTpza2lwIl19-->

---------

Co-authored-by: elastic-renovate-prod[bot] <174716857+elastic-renovate-prod[bot]@users.noreply.github.com>
Co-authored-by: kibanamachine <42973632+kibanamachine@users.noreply.github.com>
Co-authored-by: Davis McPhee <davis.mcphee@elastic.co>
Co-authored-by: Nikita Indik <nikita.indik@elastic.co>
Co-authored-by: Matthias Wilhelm <matthias.wilhelm@elastic.co>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backport:prev-minor Backport to (8.x) the previous minor version (i.e. one version back from main) release_note:skip Skip the PR/issue when compiling release notes Team:DataDiscovery Discover, search (e.g. data plugin and KQL), data views, saved searches. For ES|QL, use Team:ES|QL. v8.18.0 v9.0.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants