diff --git a/modules/markup/sanitizer_default.go b/modules/markup/sanitizer_default.go index 657dfd130e5..1d4a062059f 100644 --- a/modules/markup/sanitizer_default.go +++ b/modules/markup/sanitizer_default.go @@ -31,8 +31,9 @@ func (st *Sanitizer) createDefaultPolicy() *bluemonday.Policy { // Chroma always uses 1-2 letters for style names, we could tolerate it at the moment policy.AllowAttrs("class").Matching(regexp.MustCompile(`^\w{0,2}$`)).OnElements("span") - // Line numbers on codepreview + // Line numbers and paste behavior on codepreview policy.AllowAttrs("data-line-number").OnElements("span") + policy.AllowAttrs("data-paste-markdown-skip").OnElements("table") // emoji aliases for dark theme inversion policy.AllowAttrs("data-alias").OnElements("span") diff --git a/modules/markup/sanitizer_default_test.go b/modules/markup/sanitizer_default_test.go index 56d67bced77..3df87c8d73e 100644 --- a/modules/markup/sanitizer_default_test.go +++ b/modules/markup/sanitizer_default_test.go @@ -49,6 +49,8 @@ func TestSanitizer(t *testing.T) { `

Hello World

`, `

Hello World

`, `Hello World`, `Hello World`, + `
1
`, `
1
`, + // Org mode status of list items. `
  • `, `
  • `, `
  • `, `
  • `, diff --git a/routers/web/repo/setting/lfs.go b/routers/web/repo/setting/lfs.go index 98f0f7530a7..e72aef67f1a 100644 --- a/routers/web/repo/setting/lfs.go +++ b/routers/web/repo/setting/lfs.go @@ -290,7 +290,7 @@ func LFSFileGet(ctx *context.Context) { escapeStatus, fileContentHTML := charset.EscapeControlHTML(fileContentHTML, ctx.Locale) output := &htmlutil.HTMLBuilder{} - output.WriteHTML(``) + output.WriteHTML(`
    `) writeLine := func(lineNum int, line template.HTML) { output.WriteFormatf(``, lineNum, line) } diff --git a/services/markup/renderhelper_codepreview_test.go b/services/markup/renderhelper_codepreview_test.go index 954b403654d..114314b2573 100644 --- a/services/markup/renderhelper_codepreview_test.go +++ b/services/markup/renderhelper_codepreview_test.go @@ -34,7 +34,7 @@ func TestRenderHelperCodePreview(t *testing.T) { repo1/README.md repo.code_preview_line_from_to:1,2,65f1bf27bc -
    %d%s
    +
    # repo1 @@ -63,7 +63,7 @@ func TestRenderHelperCodePreview(t *testing.T) { repo1/README.md repo.code_preview_line_in:1,65f1bf27bc
    - +
    # repo1 diff --git a/templates/base/markup_codepreview.tmpl b/templates/base/markup_codepreview.tmpl index 4c04b5092c7..df21cd75446 100644 --- a/templates/base/markup_codepreview.tmpl +++ b/templates/base/markup_codepreview.tmpl @@ -8,7 +8,7 @@ {{ctx.Locale.Tr "repo.code_preview_line_from_to" .LineStart .LineStop $link}} {{- end}}
    - +
    {{- range $idx, $line := .HighlightLines -}} diff --git a/templates/repo/blame.tmpl b/templates/repo/blame.tmpl index a8cc5dce4eb..7bf8595763e 100644 --- a/templates/repo/blame.tmpl +++ b/templates/repo/blame.tmpl @@ -35,7 +35,7 @@ {{else if not .FileSize}} {{template "shared/fileisempty"}} {{else}} -
    +
    {{range $row := .BlameRows}} diff --git a/templates/repo/diff/box.tmpl b/templates/repo/diff/box.tmpl index 9145c09c216..502954cd83d 100644 --- a/templates/repo/diff/box.tmpl +++ b/templates/repo/diff/box.tmpl @@ -191,7 +191,7 @@ {{end}} {{else if $file.Sections}} -
    +
    {{if $.IsSplitStyle}} {{template "repo/diff/section_split" dict "file" . "root" $}} {{else}} diff --git a/templates/repo/editor/diff_preview.tmpl b/templates/repo/editor/diff_preview.tmpl index fd543a5ab96..3f0550fc597 100644 --- a/templates/repo/editor/diff_preview.tmpl +++ b/templates/repo/editor/diff_preview.tmpl @@ -2,7 +2,7 @@
    -
    +
    {{template "repo/diff/section_unified" dict "file" .File "root" $}} diff --git a/templates/repo/issue/view_content/conversation.tmpl b/templates/repo/issue/view_content/conversation.tmpl index 429350fcd77..b718da00122 100644 --- a/templates/repo/issue/view_content/conversation.tmpl +++ b/templates/repo/issue/view_content/conversation.tmpl @@ -47,7 +47,7 @@ The variables in "ctx.Data" are different in each case, making this template fra
    -
    +
    {{template "repo/diff/section_unified" dict "file" $file "root" $}} diff --git a/templates/repo/view_file.tmpl b/templates/repo/view_file.tmpl index 7a42e3a815d..cccb90a6bc0 100644 --- a/templates/repo/view_file.tmpl +++ b/templates/repo/view_file.tmpl @@ -105,7 +105,7 @@ {{else if .IsPlainText}}
    {{if .FileContent}}{{.FileContent}}{{end}}
    {{else if .FileContent}} -
    +
    {{range $idx, $code := .FileContent}} {{$line := Eval $idx "+" 1}} diff --git a/templates/shared/searchfile.tmpl b/templates/shared/searchfile.tmpl index 280584e4d1f..241e6a95caa 100644 --- a/templates/shared/searchfile.tmpl +++ b/templates/shared/searchfile.tmpl @@ -1,5 +1,5 @@
    -
    +
    {{range .SearchResult.Lines}} diff --git a/tests/e2e/pr-diff-copy.test.ts b/tests/e2e/pr-diff-copy.test.ts new file mode 100644 index 00000000000..443e2d7d86b --- /dev/null +++ b/tests/e2e/pr-diff-copy.test.ts @@ -0,0 +1,25 @@ +import {env} from 'node:process'; +import {test, expect} from '@playwright/test'; +import {apiCreateFiles, apiCreatePR, apiCreateRepo, login, randomString} from './utils.ts'; + +test('a copied pull request diff pastes as text', async ({page, request}) => { + const repoName = `e2e-pr-diff-copy-${randomString(8)}`; + const owner = env.GITEA_TEST_E2E_USER; + const [index] = await Promise.all([ + (async () => { + await apiCreateRepo(request, {name: repoName}); + await apiCreateFiles(request, owner, repoName, [{path: 'copy.txt', content: 'one | two\n'}], {branch: 'main', newBranch: 'feat'}); + return apiCreatePR(request, owner, repoName, 'feat', 'main', 'title'); + })(), + login(page), + ]); + await page.goto(`/${owner}/${repoName}/pulls/${index}/files`); + + await page.getByRole('main').selectText(); + await page.keyboard.press('ControlOrMeta+KeyC'); + await page.getByRole('button', {name: 'Review', exact: true}).click(); + const comment = page.getByRole('textbox', {name: 'Review comment'}); + await comment.press('ControlOrMeta+KeyV'); + await expect(comment).toHaveValue(/one \| two/); + await expect(comment).not.toHaveValue(/one \\\| two/); // paste-markdown also inserts the table until https://github.com/github/paste-markdown/pull/128 +});