Fix: Ensure equalities processed via new processEqualities hook (Fixes #219)#224
Merged
wumpz merged 1 commit intojava-diff-utils:masterfrom Dec 10, 2025
Merged
Conversation
…rocessed for unchanged lines (Fixes java-diff-utils#219) - Introduces a new protected method `processEqualities(String)` in DiffRowGenerator - Builder exposes `.processEqualities(Function<String,String>)` - Equal (unchanged) lines now invoke processEqualities() - Inline diffs remain unchanged (as expected in Option 3) - Added new test suite DiffRowGeneratorEqualitiesTest - Updated documentation and Javadoc for new extension point - Fixes java-diff-utils#219 (HTML escaping issue when inline diff by word)
Collaborator
|
thx for your pr |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
This PR introduces a new extension point,
processEqualities(), insideDiffRowGeneratorto address the HTML-escaping issue described in #219.Previously, equal (unchanged) segments were passed through HTML normalization only once.
Because
<and>were normalized to&lt;and&gt;, equalities that began with&caused incorrect inline diff grouping (e.g.,&lt;vs&gt;). This produced invalid HTML wheninlineDiffByWord(true)was used.What This PR Changes
✔ Adds a new protected hook:
✔ All equality chunks now pass through this hook before becoming
DiffRow(Tag.EQUAL, ...).✔ Default behavior is no modification (fully backward compatible).
✔ Users can override this hook to customize HTML or text transformations after diffing, solving the core issue.
Why this Fix Works
The problem in #219 occurs because the diff logic compares normalized text, but the final output does not normalize equal segments the same way as diffs.
By exposing
processEqualities(), we give users a consistent post-diff transformation path.This ensures that equal text is handled symmetrically to diffed text and prevents HTML-breaking cases like
&lt;/&gt;being partially diffed.Backward Compatibility
Tests Included
✔ Added
DiffRowGeneratorEqualitiesTest✔ Verifies that:
processEqualities()Fixes
Fixes #219