summaryrefslogtreecommitdiffstats
path: root/modules/markup/html_internal_test.go
diff options
context:
space:
mode:
authormrsdizzie <info@mrsdizzie.com>2019-04-07 07:18:16 -0400
committerzeripath <art27@cantab.net>2019-04-07 12:18:16 +0100
commit6293736d02992ef317c0f1ffc875cdccf0fd5837 (patch)
tree00fbf299043df33893f1c173a824c4f45d13eb30 /modules/markup/html_internal_test.go
parent5422f23ed8174661b6e658250e4007b7fdf0d603 (diff)
downloadgitea-6293736d02992ef317c0f1ffc875cdccf0fd5837.tar.gz
gitea-6293736d02992ef317c0f1ffc875cdccf0fd5837.zip
Use stricter boundaries for auto-link detection (#6522)
* Use stricter boundaries for auto-link detection Currently autolinks use \W for boundary detection which creates many situations of inserting links into places they don't belong (paths, URLs, UUIDs, etc...) This fixes that by replacing \W and only allowing these matches to touch an open paren or bracket (matching what seems to be Github behavior) in addition to whitespace and start of line. Similar for ending boundary as well. Fixes #6149 (and probably others) * Update test Replace incorrect test with a value that is a valid username, based on: "Username should contain only alphanumeric, dash ('-'), underscore ('_') and dot ('.') characters." * Also allow for period at the end Matching Github behavior * Fix email regex to work properly with specificed boundaries Create a specific capture group for email address and then use FindStringSubmatchIndex to allow for non-matching patterns as boundaries. * Add Tests Add tests for new behavior -- including tests for email addresses which were absent before.
Diffstat (limited to 'modules/markup/html_internal_test.go')
-rw-r--r--modules/markup/html_internal_test.go20
1 files changed, 18 insertions, 2 deletions
diff --git a/modules/markup/html_internal_test.go b/modules/markup/html_internal_test.go
index b8612eb2bb..cc261318eb 100644
--- a/modules/markup/html_internal_test.go
+++ b/modules/markup/html_internal_test.go
@@ -71,6 +71,7 @@ func TestRender_IssueIndexPattern(t *testing.T) {
test("test#1234")
test("#1234test")
test(" test #1234test")
+ test("/home/gitea/#1234")
// should not render issue mention without leading space
test("test#54321 issue")
@@ -103,9 +104,11 @@ func TestRender_IssueIndexPattern2(t *testing.T) {
test("#1234 test", "%s test", 1234)
test("test #8 issue", "test %s issue", 8)
test("test issue #1234", "test issue %s", 1234)
+ test("fixes issue #1234.", "fixes issue %s.", 1234)
- // should render mentions in parentheses
+ // should render mentions in parentheses / brackets
test("(#54321 issue)", "(%s issue)", 54321)
+ test("[#54321 issue]", "[%s issue]", 54321)
test("test (#9801 extra) issue", "test (%s extra) issue", 9801)
test("test (#1)", "test (%s)", 1)
@@ -253,10 +256,14 @@ func TestRegExp_sha1CurrentPattern(t *testing.T) {
trueTestCases := []string{
"d8a994ef243349f321568f9e36d5c3f444b99cae",
"abcdefabcdefabcdefabcdefabcdefabcdefabcd",
+ "(abcdefabcdefabcdefabcdefabcdefabcdefabcd)",
+ "[abcdefabcdefabcdefabcdefabcdefabcdefabcd]",
+ "abcdefabcdefabcdefabcdefabcdefabcdefabcd.",
}
falseTestCases := []string{
"test",
"abcdefg",
+ "e59ff077-2d03-4e6b-964d-63fbaea81f",
"abcdefghijklmnopqrstuvwxyzabcdefghijklmn",
"abcdefghijklmnopqrstuvwxyzabcdefghijklmO",
}
@@ -309,7 +316,9 @@ func TestRegExp_mentionPattern(t *testing.T) {
"@ANT_123",
"@xxx-DiN0-z-A..uru..s-xxx",
" @lol ",
- " @Te/st",
+ " @Te-st",
+ "(@gitea)",
+ "[@gitea]",
}
falseTestCases := []string{
"@ 0",
@@ -317,6 +326,8 @@ func TestRegExp_mentionPattern(t *testing.T) {
"@",
"",
"ABC",
+ "/home/gitea/@gitea",
+ "\"@gitea\"",
}
for _, testCase := range trueTestCases {
@@ -335,6 +346,9 @@ func TestRegExp_issueAlphanumericPattern(t *testing.T) {
"A-1",
"RC-80",
"ABCDEFGHIJ-1234567890987654321234567890",
+ "ABC-123.",
+ "(ABC-123)",
+ "[ABC-123]",
}
falseTestCases := []string{
"RC-08",
@@ -347,6 +361,8 @@ func TestRegExp_issueAlphanumericPattern(t *testing.T) {
"ABC",
"GG-",
"rm-1",
+ "/home/gitea/ABC-1234",
+ "MY-STRING-ABC-123",
}
for _, testCase := range trueTestCases {