Allow square brackets in external issue patterns (#3408)

* Allow square brackets in external issue patterns

* Added false test cases for checklist elements
This commit is contained in:
Christian Köberl 2018-02-03 10:51:02 +01:00 committed by Lauris BH
parent e08b3a592e
commit e9e2a9cdcc
2 changed files with 7 additions and 2 deletions

View File

@ -38,9 +38,9 @@ var (
MentionPattern = regexp.MustCompile(`(\s|^|\W)@[0-9a-zA-Z-_\.]+`) MentionPattern = regexp.MustCompile(`(\s|^|\W)@[0-9a-zA-Z-_\.]+`)
// IssueNumericPattern matches string that references to a numeric issue, e.g. #1287 // IssueNumericPattern matches string that references to a numeric issue, e.g. #1287
IssueNumericPattern = regexp.MustCompile(`( |^|\()#[0-9]+\b`) IssueNumericPattern = regexp.MustCompile(`( |^|\(|\[)#[0-9]+\b`)
// IssueAlphanumericPattern matches string that references to an alphanumeric issue, e.g. ABC-1234 // IssueAlphanumericPattern matches string that references to an alphanumeric issue, e.g. ABC-1234
IssueAlphanumericPattern = regexp.MustCompile(`( |^|\()[A-Z]{1,10}-[1-9][0-9]*\b`) IssueAlphanumericPattern = regexp.MustCompile(`( |^|\(|\[)[A-Z]{1,10}-[1-9][0-9]*\b`)
// CrossReferenceIssueNumericPattern matches string that references a numeric issue in a different repository // CrossReferenceIssueNumericPattern matches string that references a numeric issue in a different repository
// e.g. gogits/gogs#12345 // e.g. gogits/gogs#12345
CrossReferenceIssueNumericPattern = regexp.MustCompile(`( |^)[0-9a-zA-Z-_\.]+/[0-9a-zA-Z-_\.]+#[0-9]+\b`) CrossReferenceIssueNumericPattern = regexp.MustCompile(`( |^)[0-9a-zA-Z-_\.]+/[0-9a-zA-Z-_\.]+#[0-9]+\b`)

View File

@ -345,6 +345,7 @@ func TestRegExp_IssueNumericPattern(t *testing.T) {
"#1234", "#1234",
"#0", "#0",
"#1234567890987654321", "#1234567890987654321",
"[#1234]",
} }
falseTestCases := []string{ falseTestCases := []string{
"# 1234", "# 1234",
@ -355,6 +356,8 @@ func TestRegExp_IssueNumericPattern(t *testing.T) {
"#1A2B", "#1A2B",
"", "",
"ABC", "ABC",
"[]",
"[x]",
} }
for _, testCase := range trueTestCases { for _, testCase := range trueTestCases {
@ -371,6 +374,7 @@ func TestRegExp_IssueAlphanumericPattern(t *testing.T) {
"A-1", "A-1",
"RC-80", "RC-80",
"ABCDEFGHIJ-1234567890987654321234567890", "ABCDEFGHIJ-1234567890987654321234567890",
"[JIRA-134]",
} }
falseTestCases := []string{ falseTestCases := []string{
"RC-08", "RC-08",
@ -383,6 +387,7 @@ func TestRegExp_IssueAlphanumericPattern(t *testing.T) {
"ABC", "ABC",
"GG-", "GG-",
"rm-1", "rm-1",
"[]",
} }
for _, testCase := range trueTestCases { for _, testCase := range trueTestCases {