Skip to content

Commit b6f945d

Browse files
committed
remove
1 parent efa54ed commit b6f945d

File tree

10 files changed

+15
-16
lines changed

10 files changed

+15
-16
lines changed

modules/charset/escape.go

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
package charset
99

1010
import (
11-
"context"
1211
"html/template"
1312
"io"
1413
"strings"
@@ -22,14 +21,14 @@ import (
2221
const RuneNBSP = 0xa0
2322

2423
// EscapeControlHTML escapes the unicode control sequences in a provided html document
25-
func EscapeControlHTML(ctx context.Context, html template.HTML, locale translation.Locale, allowed ...rune) (escaped *EscapeStatus, output template.HTML) {
24+
func EscapeControlHTML(html template.HTML, locale translation.Locale, allowed ...rune) (escaped *EscapeStatus, output template.HTML) {
2625
sb := &strings.Builder{}
27-
escaped, _ = EscapeControlReader(ctx, strings.NewReader(string(html)), sb, locale, allowed...) // err has been handled in EscapeControlReader
26+
escaped, _ = EscapeControlReader(strings.NewReader(string(html)), sb, locale, allowed...) // err has been handled in EscapeControlReader
2827
return escaped, template.HTML(sb.String())
2928
}
3029

3130
// EscapeControlReader escapes the unicode control sequences in a provided reader of HTML content and writer in a locale and returns the findings as an EscapeStatus
32-
func EscapeControlReader(ctx context.Context, reader io.Reader, writer io.Writer, locale translation.Locale, allowed ...rune) (escaped *EscapeStatus, err error) {
31+
func EscapeControlReader(reader io.Reader, writer io.Writer, locale translation.Locale, allowed ...rune) (escaped *EscapeStatus, err error) {
3332
if !setting.UI.AmbiguousUnicodeDetection {
3433
_, err = io.Copy(writer, reader)
3534
return &EscapeStatus{}, err

modules/charset/escape_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ func TestEscapeControlReader(t *testing.T) {
161161
for _, tt := range tests {
162162
t.Run(tt.name, func(t *testing.T) {
163163
output := &strings.Builder{}
164-
status, err := EscapeControlReader(t.Context(), strings.NewReader(tt.text), output, &translation.MockLocale{})
164+
status, err := EscapeControlReader(strings.NewReader(tt.text), output, &translation.MockLocale{})
165165
assert.NoError(t, err)
166166
assert.Equal(t, tt.status, *status)
167167
outStr := output.String()
@@ -173,9 +173,9 @@ func TestEscapeControlReader(t *testing.T) {
173173

174174
func TestSettingAmbiguousUnicodeDetection(t *testing.T) {
175175
defer test.MockVariableValue(&setting.UI.AmbiguousUnicodeDetection, true)()
176-
_, out := EscapeControlHTML(t.Context(), "a test", &translation.MockLocale{})
176+
_, out := EscapeControlHTML("a test", &translation.MockLocale{})
177177
assert.EqualValues(t, `a<span class="escaped-code-point" data-escaped="[U+00A0]"><span class="char"> </span></span>test`, out)
178178
setting.UI.AmbiguousUnicodeDetection = false
179-
_, out = EscapeControlHTML(t.Context(), "a test", &translation.MockLocale{})
179+
_, out = EscapeControlHTML("a test", &translation.MockLocale{})
180180
assert.EqualValues(t, `a test`, out)
181181
}

routers/web/repo/blame.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -309,7 +309,7 @@ func renderBlame(ctx *context.Context, blameParts []*git.BlamePart, commitNames
309309
lexerName = lexerNameForLine
310310
}
311311

312-
br.EscapeStatus, br.Code = charset.EscapeControlHTML(ctx, line, ctx.Locale)
312+
br.EscapeStatus, br.Code = charset.EscapeControlHTML(line, ctx.Locale)
313313
rows = append(rows, br)
314314
escapeStatus = escapeStatus.Or(br.EscapeStatus)
315315
}

routers/web/repo/setting/lfs.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -310,7 +310,7 @@ func LFSFileGet(ctx *context.Context) {
310310
// Building code view blocks with line number on server side.
311311
// FIXME: the logic is not right here: it first calls EscapeControlReader then calls HTMLEscapeString: double-escaping
312312
escapedContent := &bytes.Buffer{}
313-
ctx.Data["EscapeStatus"], _ = charset.EscapeControlReader(ctx, rd, escapedContent, ctx.Locale)
313+
ctx.Data["EscapeStatus"], _ = charset.EscapeControlReader(rd, escapedContent, ctx.Locale)
314314

315315
var output bytes.Buffer
316316
lines := strings.Split(escapedContent.String(), "\n")

routers/web/repo/view.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ func markupRender(ctx *context.Context, renderCtx *markup.RenderContext, input i
150150
go func() {
151151
sb := &strings.Builder{}
152152
// We allow NBSP here this is rendered
153-
escaped, _ = charset.EscapeControlReader(ctx, markupRd, sb, ctx.Locale, charset.RuneNBSP)
153+
escaped, _ = charset.EscapeControlReader(markupRd, sb, ctx.Locale, charset.RuneNBSP)
154154
output = template.HTML(sb.String())
155155
close(done)
156156
}()

routers/web/repo/view_file.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,7 @@ func prepareToRenderFile(ctx *context.Context, entry *git.TreeEntry) {
216216
status := &charset.EscapeStatus{}
217217
statuses := make([]*charset.EscapeStatus, len(fileContent))
218218
for i, line := range fileContent {
219-
statuses[i], fileContent[i] = charset.EscapeControlHTML(ctx, line, ctx.Locale)
219+
statuses[i], fileContent[i] = charset.EscapeControlHTML(line, ctx.Locale)
220220
status = status.Or(statuses[i])
221221
}
222222
ctx.Data["EscapeStatus"] = status

routers/web/repo/view_readme.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,7 @@ func prepareToRenderReadmeFile(ctx *context.Context, subfolder string, readmeFil
209209
log.Error("Read readme content failed: %v", err)
210210
}
211211
contentEscaped := template.HTMLEscapeString(util.UnsafeBytesToString(content))
212-
ctx.Data["EscapeStatus"], ctx.Data["FileContent"] = charset.EscapeControlHTML(ctx, template.HTML(contentEscaped), ctx.Locale)
212+
ctx.Data["EscapeStatus"], ctx.Data["FileContent"] = charset.EscapeControlHTML(template.HTML(contentEscaped), ctx.Locale)
213213
}
214214

215215
if !fInfo.isLFSFile && ctx.Repo.CanEnableEditor(ctx, ctx.Doer) {

routers/web/repo/wiki.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -300,7 +300,7 @@ func renderViewPage(ctx *context.Context) (*git.Repository, *git.TreeEntry) {
300300
done := make(chan struct{})
301301
go func() {
302302
// We allow NBSP here this is rendered
303-
escaped, _ = charset.EscapeControlReader(ctx, markupRd, buf, ctx.Locale, charset.RuneNBSP)
303+
escaped, _ = charset.EscapeControlReader(markupRd, buf, ctx.Locale, charset.RuneNBSP)
304304
output = buf.String()
305305
buf.Reset()
306306
close(done)

services/gitdiff/gitdiff.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -285,14 +285,14 @@ type DiffInline struct {
285285

286286
// DiffInlineWithUnicodeEscape makes a DiffInline with hidden unicode characters escaped
287287
func DiffInlineWithUnicodeEscape(ctx context.Context, s template.HTML, locale translation.Locale) DiffInline {
288-
status, content := charset.EscapeControlHTML(ctx, s, locale)
288+
status, content := charset.EscapeControlHTML(s, locale)
289289
return DiffInline{EscapeStatus: status, Content: content}
290290
}
291291

292292
// DiffInlineWithHighlightCode makes a DiffInline with code highlight and hidden unicode characters escaped
293293
func DiffInlineWithHighlightCode(ctx context.Context, fileName, language, code string, locale translation.Locale) DiffInline {
294294
highlighted, _ := highlight.Code(fileName, language, code)
295-
status, content := charset.EscapeControlHTML(ctx, highlighted, locale)
295+
status, content := charset.EscapeControlHTML(highlighted, locale)
296296
return DiffInline{EscapeStatus: status, Content: content}
297297
}
298298

services/markup/renderhelper_codepreview.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ func renderRepoFileCodePreview(ctx context.Context, opts markup.RenderCodePrevie
101101
escapeStatus := &charset.EscapeStatus{}
102102
lineEscapeStatus := make([]*charset.EscapeStatus, len(highlightLines))
103103
for i, hl := range highlightLines {
104-
lineEscapeStatus[i], hl.FormattedContent = charset.EscapeControlHTML(ctx, hl.FormattedContent, webCtx.Base.Locale, charset.RuneNBSP)
104+
lineEscapeStatus[i], hl.FormattedContent = charset.EscapeControlHTML(hl.FormattedContent, webCtx.Base.Locale, charset.RuneNBSP)
105105
escapeStatus = escapeStatus.Or(lineEscapeStatus[i])
106106
}
107107

0 commit comments

Comments
 (0)