-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
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
Display issue in commit diff #14231
Comments
@fnetX i see that for your case as noted by your screenshot, the wrong color for brackets at |
You mean the brackets have the wrong colour? Yes, but that's because the whole HTML is messed up here. |
diff --git a/services/gitdiff/gitdiff_test.go b/services/gitdiff/gitdiff_test.go
index cd7b2273c..813260f3b 100644
--- a/services/gitdiff/gitdiff_test.go
+++ b/services/gitdiff/gitdiff_test.go
@@ -15,6 +15,7 @@ import (
"code.gitea.io/gitea/models"
"code.gitea.io/gitea/modules/git"
+ "code.gitea.io/gitea/modules/highlight"
"code.gitea.io/gitea/modules/setting"
dmp "github.com/sergi/go-diff/diffmatchpatch"
"github.com/stretchr/testify/assert"
@@ -101,6 +102,15 @@ func TestDiffToHTML(t *testing.T) {
}, DiffLineAdd))
}
+func TestDiffToHTML_14231(t *testing.T) {
+ setting.Cfg = ini.Empty()
+
+ diffRecord := diffMatchPatch.DiffMain(highlight.Code("main.v", " run()\n"), highlight.Code("main.v", " run(db)\n"), true)
+ diffRecord = diffMatchPatch.DiffCleanupEfficiency(diffRecord)
+ assertEqual(t, ` <span class="n">run</span><span class="added-code"><span class="o">(</span><span class="n">db</span><span class="o">)</span></span>`,
+ diffToHTML("main.v", diffRecord, DiffLineAdd))
+}
+
func TestParsePatch_singlefile(t *testing.T) {
type testcase struct {
name string will add a testcase to work with |
the diffRecord is:
|
I honestly think the regexp approach cannot work here. Record 2 here is an attribute in deleted case and is text in added case. |
In my previous reverted pr I attempted to do the kind of necessary fixup. Now, we have several options:
|
thinking on here - I think the fixup technique is the correct answer. Intention of the proposed algo - No Equals/Insert/Delete block starts or ends within an element, entity or even within an unclosed span. (EDIT: this last case needs a bit more thought)
I think that would do it. |
Gitea runs diff on highlighted code fragment for each line in order to provide code highlight diffs. Unfortunately this diff algorithm is not aware that span tags and entities are atomic and cannot be split. The current fixup code makes some attempt to fix these broken tags however, it cannot handle situations where a tag is split over multiple blocks. This PR provides a more algorithmic fixup mechanism whereby spans and entities are completely coalesced into their respective blocks. This may result in a incompletely reduced diff but - it will definitely prevent the broken entities and spans that are currently possible. As a result of this fixup several inconsistencies were discovered in our testcases and these were also fixed. Fix go-gitea#14231 Signed-off-by: Andrew Thornton <[email protected]>
Gitea runs diff on highlighted code fragment for each line in order to provide code highlight diffs. Unfortunately this diff algorithm is not aware that span tags and entities are atomic and cannot be split. The current fixup code makes some attempt to fix these broken tags however, it cannot handle situations where a tag is split over multiple blocks. This PR provides a more algorithmic fixup mechanism whereby spans and entities are completely coalesced into their respective blocks. This may result in a incompletely reduced diff but - it will definitely prevent the broken entities and spans that are currently possible. As a result of this fixup several inconsistencies were discovered in our testcases and these were also fixed. Fix #14231 Signed-off-by: Andrew Thornton <[email protected]>
@zeripath Thank you! |
Backport go-gitea#14678 Gitea runs diff on highlighted code fragment for each line in order to provide code highlight diffs. Unfortunately this diff algorithm is not aware that span tags and entities are atomic and cannot be split. The current fixup code makes some attempt to fix these broken tags however, it cannot handle situations where a tag is split over multiple blocks. This PR provides a more algorithmic fixup mechanism whereby spans and entities are completely coalesced into their respective blocks. This may result in a incompletely reduced diff but - it will definitely prevent the broken entities and spans that are currently possible. As a result of this fixup several inconsistencies were discovered in our testcases and these were also fixed. Fix go-gitea#14231 Signed-off-by: Andrew Thornton <[email protected]>
@fnetX Sorry it's taken so long. It was unfortunately a non-trivial bug. |
I should also add I was significantly delayed by breaking my left hand over the Christmas period. |
Backport #14678 Gitea runs diff on highlighted code fragment for each line in order to provide code highlight diffs. Unfortunately this diff algorithm is not aware that span tags and entities are atomic and cannot be split. The current fixup code makes some attempt to fix these broken tags however, it cannot handle situations where a tag is split over multiple blocks. This PR provides a more algorithmic fixup mechanism whereby spans and entities are completely coalesced into their respective blocks. This may result in a incompletely reduced diff but - it will definitely prevent the broken entities and spans that are currently possible. As a result of this fixup several inconsistencies were discovered in our testcases and these were also fixed. Fix #14231 Signed-off-by: Andrew Thornton <[email protected]> Co-authored-by: 6543 <[email protected]>
Description
First reported on https://codeberg.org/Codeberg/Community/issues/374
Screenshots
Thank you a lot.
The text was updated successfully, but these errors were encountered: