mirror of
https://github.com/go-gitea/gitea.git
synced 2025-04-21 00:48:43 +03:00
@ -85,7 +85,8 @@ var globalVars = sync.OnceValue(func() *globalVarsType {
|
|||||||
// codePreviewPattern matches "http://domain/.../{owner}/{repo}/src/commit/{commit}/{filepath}#L10-L20"
|
// codePreviewPattern matches "http://domain/.../{owner}/{repo}/src/commit/{commit}/{filepath}#L10-L20"
|
||||||
v.codePreviewPattern = regexp.MustCompile(`https?://\S+/([^\s/]+)/([^\s/]+)/src/commit/([0-9a-f]{7,64})(/\S+)#(L\d+(-L\d+)?)`)
|
v.codePreviewPattern = regexp.MustCompile(`https?://\S+/([^\s/]+)/([^\s/]+)/src/commit/([0-9a-f]{7,64})(/\S+)#(L\d+(-L\d+)?)`)
|
||||||
|
|
||||||
v.tagCleaner = regexp.MustCompile(`<((?:/?\w+/\w+)|(?:/[\w ]+/)|(/?[hH][tT][mM][lL]\b)|(/?[hH][eE][aA][dD]\b))`)
|
// cleans: "<foo/bar", "<any words/", ("<html", "<head", "<script", "<style")
|
||||||
|
v.tagCleaner = regexp.MustCompile(`(?i)<(/?\w+/\w+|/[\w ]+/|/?(html|head|script|style\b))`)
|
||||||
v.nulCleaner = strings.NewReplacer("\000", "")
|
v.nulCleaner = strings.NewReplacer("\000", "")
|
||||||
return v
|
return v
|
||||||
})
|
})
|
||||||
|
@ -469,7 +469,7 @@ func Test_ParseClusterFuzz(t *testing.T) {
|
|||||||
assert.NotContains(t, res.String(), "<html")
|
assert.NotContains(t, res.String(), "<html")
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestPostProcess_RenderDocument(t *testing.T) {
|
func TestPostProcess(t *testing.T) {
|
||||||
setting.StaticURLPrefix = markup.TestAppURL // can't run standalone
|
setting.StaticURLPrefix = markup.TestAppURL // can't run standalone
|
||||||
defer testModule.MockVariableValue(&markup.RenderBehaviorForTesting.DisableAdditionalAttributes, true)()
|
defer testModule.MockVariableValue(&markup.RenderBehaviorForTesting.DisableAdditionalAttributes, true)()
|
||||||
|
|
||||||
@ -480,7 +480,7 @@ func TestPostProcess_RenderDocument(t *testing.T) {
|
|||||||
assert.Equal(t, strings.TrimSpace(expected), strings.TrimSpace(res.String()))
|
assert.Equal(t, strings.TrimSpace(expected), strings.TrimSpace(res.String()))
|
||||||
}
|
}
|
||||||
|
|
||||||
// Issue index shouldn't be post processing in a document.
|
// Issue index shouldn't be post-processing in a document.
|
||||||
test(
|
test(
|
||||||
"#1",
|
"#1",
|
||||||
"#1")
|
"#1")
|
||||||
@ -490,7 +490,7 @@ func TestPostProcess_RenderDocument(t *testing.T) {
|
|||||||
"go-gitea/gitea#12345",
|
"go-gitea/gitea#12345",
|
||||||
`<a href="/go-gitea/gitea/issues/12345" class="ref-issue">go-gitea/gitea#12345</a>`)
|
`<a href="/go-gitea/gitea/issues/12345" class="ref-issue">go-gitea/gitea#12345</a>`)
|
||||||
|
|
||||||
// Test that other post processing still works.
|
// Test that other post-processing still works.
|
||||||
test(
|
test(
|
||||||
":gitea:",
|
":gitea:",
|
||||||
`<span class="emoji" aria-label="gitea"><img alt=":gitea:" src="`+setting.StaticURLPrefix+`/assets/img/emoji/gitea.png"/></span>`)
|
`<span class="emoji" aria-label="gitea"><img alt=":gitea:" src="`+setting.StaticURLPrefix+`/assets/img/emoji/gitea.png"/></span>`)
|
||||||
@ -499,6 +499,12 @@ func TestPostProcess_RenderDocument(t *testing.T) {
|
|||||||
`Some text with <span class="emoji" aria-label="grinning face with smiling eyes">😄</span> in the middle`)
|
`Some text with <span class="emoji" aria-label="grinning face with smiling eyes">😄</span> in the middle`)
|
||||||
test("http://localhost:3000/person/repo/issues/4#issuecomment-1234",
|
test("http://localhost:3000/person/repo/issues/4#issuecomment-1234",
|
||||||
`<a href="http://localhost:3000/person/repo/issues/4#issuecomment-1234" class="ref-issue">person/repo#4 (comment)</a>`)
|
`<a href="http://localhost:3000/person/repo/issues/4#issuecomment-1234" class="ref-issue">person/repo#4 (comment)</a>`)
|
||||||
|
|
||||||
|
// special tags, GitHub's behavior, and for unclosed tags, output as text content as much as possible
|
||||||
|
test("<script>a", `<script>a`)
|
||||||
|
test("<script>a</script>", `<script>a</script>`)
|
||||||
|
test("<STYLE>a", `<STYLE>a`)
|
||||||
|
test("<style>a</STYLE>", `<style>a</STYLE>`)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestIssue16020(t *testing.T) {
|
func TestIssue16020(t *testing.T) {
|
||||||
|
Reference in New Issue
Block a user