Skip to content

Commit 4afb1cc

Browse files
committed
always output the code/name part of the html entities if the placeholders are exhausted.
1 parent dc74baf commit 4afb1cc

File tree

2 files changed

+18
-2
lines changed

2 files changed

+18
-2
lines changed

services/gitdiff/highlightdiff.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,8 @@ func (hcd *highlightCodeDiff) convertToPlaceholders(htmlCode string) string {
169169
hcd.placeholderOverflowCount++
170170
if strings.HasPrefix(token, "&") {
171171
// when the token is a html entity, something must be outputted even if there is no placeholder.
172-
res.WriteRune(0xFFFD) // replacement character TODO: how to handle this case more gracefully?
172+
res.WriteRune(0xFFFD) // replacement character TODO: how to handle this case more gracefully?
173+
res.WriteString(token[1:]) // still output the entity code part, otherwise there will be no diff result.
173174
}
174175
}
175176
}

services/gitdiff/highlightdiff_test.go

+16-1
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,22 @@ func TestDiffWithHighlightPlaceholderExhausted(t *testing.T) {
6363
``,
6464
)
6565
output := diffToHTML(nil, diffs, DiffLineDel)
66-
expected := fmt.Sprintf(`<span class="removed-code">%s</span>`, "\uFFFD")
66+
expected := fmt.Sprintf(`<span class="removed-code">%s#39;</span>`, "\uFFFD")
67+
assert.Equal(t, expected, output)
68+
69+
hcd = newHighlightCodeDiff()
70+
hcd.placeholderMaxCount = 0
71+
diffs = hcd.diffWithHighlight(
72+
"main.js", "",
73+
"a < b",
74+
"a > b",
75+
)
76+
output = diffToHTML(nil, diffs, DiffLineDel)
77+
expected = fmt.Sprintf(`a %s<span class="removed-code">l</span>t; b`, "\uFFFD")
78+
assert.Equal(t, expected, output)
79+
80+
output = diffToHTML(nil, diffs, DiffLineAdd)
81+
expected = fmt.Sprintf(`a %s<span class="added-code">g</span>t; b`, "\uFFFD")
6782
assert.Equal(t, expected, output)
6883
}
6984

0 commit comments

Comments
 (0)