mirror of
https://github.com/go-gitea/gitea
synced 2024-12-24 03:46:08 +01:00
Regex test cases: https://regex101.com/r/mVbPxM/2/ fixes #14223
This commit is contained in:
parent
450b32c1a1
commit
4be59eb5d9
@ -43,7 +43,7 @@ var (
|
|||||||
// sha1CurrentPattern matches string that represents a commit SHA, e.g. d8a994ef243349f321568f9e36d5c3f444b99cae
|
// sha1CurrentPattern matches string that represents a commit SHA, e.g. d8a994ef243349f321568f9e36d5c3f444b99cae
|
||||||
// Although SHA1 hashes are 40 chars long, the regex matches the hash from 7 to 40 chars in length
|
// Although SHA1 hashes are 40 chars long, the regex matches the hash from 7 to 40 chars in length
|
||||||
// so that abbreviated hash links can be used as well. This matches git and github useability.
|
// so that abbreviated hash links can be used as well. This matches git and github useability.
|
||||||
sha1CurrentPattern = regexp.MustCompile(`(?:\s|^|\(|\[)([0-9a-f]{7,40})(?:\s|$|\)|\]|\.(\s|$))`)
|
sha1CurrentPattern = regexp.MustCompile(`(?:\s|^|\(|\[)([0-9a-f]{7,40})(?:\s|$|\)|\]|[.,](\s|$))`)
|
||||||
|
|
||||||
// shortLinkPattern matches short but difficult to parse [[name|link|arg=test]] syntax
|
// shortLinkPattern matches short but difficult to parse [[name|link|arg=test]] syntax
|
||||||
shortLinkPattern = regexp.MustCompile(`\[\[(.*?)\]\](\w*)`)
|
shortLinkPattern = regexp.MustCompile(`\[\[(.*?)\]\](\w*)`)
|
||||||
|
@ -46,6 +46,12 @@ func TestRender_Commits(t *testing.T) {
|
|||||||
test("/home/gitea/"+sha, "<p>/home/gitea/"+sha+"</p>")
|
test("/home/gitea/"+sha, "<p>/home/gitea/"+sha+"</p>")
|
||||||
test("deadbeef", `<p>deadbeef</p>`)
|
test("deadbeef", `<p>deadbeef</p>`)
|
||||||
test("d27ace93", `<p>d27ace93</p>`)
|
test("d27ace93", `<p>d27ace93</p>`)
|
||||||
|
test(sha[:14]+".x", `<p>`+sha[:14]+`.x</p>`)
|
||||||
|
|
||||||
|
expected14 := `<a href="` + commit[:len(commit)-(40-14)] + `" rel="nofollow"><code>` + sha[:10] + `</code></a>`
|
||||||
|
test(sha[:14]+".", `<p>`+expected14+`.</p>`)
|
||||||
|
test(sha[:14]+",", `<p>`+expected14+`,</p>`)
|
||||||
|
test("["+sha[:14]+"]", `<p>[`+expected14+`]</p>`)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestRender_CrossReferences(t *testing.T) {
|
func TestRender_CrossReferences(t *testing.T) {
|
||||||
|
Loading…
Reference in New Issue
Block a user