Skip to content

Commit

Permalink
fix: should allow 0 in the middle to end (#160)
Browse files Browse the repository at this point in the history
* fix: should allow 0 in the middle to end

* feat: tests with 0 in the middle
  • Loading branch information
lucassabreu authored Feb 28, 2024
1 parent fd9d157 commit 7d93631
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 1 deletion.
2 changes: 1 addition & 1 deletion server/constants/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ const (
CommandDelete = "delete"

// Regex to verify task link
TaskLinkRegex = `http(s)?:\/\/dev.azure.com\/[a-zA-Z0-9!@#$%^&*()_+\-=\[\]{};':"\\|,.<>\/?]*\/[a-zA-Z0-9!@#$%^&*()_+\-=\[\]{};':"\\|,.<>\/?]*\/_workitems\/edit\/[1-9]+`
TaskLinkRegex = `http(s)?:\/\/dev.azure.com\/[a-zA-Z0-9!@#$%^&*()_+\-=\[\]{};':"\\|,.<>\/?]*\/[a-zA-Z0-9!@#$%^&*()_+\-=\[\]{};':"\\|,.<>\/?]*\/_workitems\/edit\/[1-9][0-9]*`

// Regex to verify pull request link
PullRequestLinkRegex = `http(s)?:\/\/dev.azure.com\/[a-zA-Z0-9!@#$%^&*()_+\-=\[\]{};':"\\|,.<>\/?]*\/[a-zA-Z0-9!@#$%^&*()_+\-=\[\]{};':"\\|,.<>\/?]*\/_git\/[a-zA-Z0-9!@#$%^&*()_+\-=\[\]{};':"\\|,.<>\/?]*\/pullrequest\/[1-9]+`
Expand Down
64 changes: 64 additions & 0 deletions server/plugin/plugin_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,70 @@ func TestIsLinkPresent(t *testing.T) {
regex: constants.TaskLinkRegex,
expectedLink: "http://dev.azure.com/abc/xyz/_workitems/edit/1",
},
{
description: "IsLinkPresent: valid task link 5",
msg: "https://dev.azure.com/abc/xyz/_workitems/edit/10/",
expectedData: []string{"https:", "", "dev.azure.com", "abc", "xyz", "_workitems", "edit", "10"},
isValid: true,
regex: constants.TaskLinkRegex,
expectedLink: "https://dev.azure.com/abc/xyz/_workitems/edit/10",
},
{
description: "IsLinkPresent: valid task link 6",
msg: "https://dev.azure.com/abc/xyz/_workitems/edit/10",
expectedData: []string{"https:", "", "dev.azure.com", "abc", "xyz", "_workitems", "edit", "10"},
isValid: true,
regex: constants.TaskLinkRegex,
expectedLink: "https://dev.azure.com/abc/xyz/_workitems/edit/10",
},
{
description: "IsLinkPresent: valid task link 7",
msg: "http://dev.azure.com/abc/xyz/_workitems/edit/10",
expectedData: []string{"http:", "", "dev.azure.com", "abc", "xyz", "_workitems", "edit", "10"},
isValid: true,
regex: constants.TaskLinkRegex,
expectedLink: "http://dev.azure.com/abc/xyz/_workitems/edit/10",
},
{
description: "IsLinkPresent: valid task link 8",
msg: "\n\nhttp://dev.azure.com/abc/xyz/_workitems/edit/10 mock-text",
expectedData: []string{"http:", "", "dev.azure.com", "abc", "xyz", "_workitems", "edit", "10"},
isValid: true,
regex: constants.TaskLinkRegex,
expectedLink: "http://dev.azure.com/abc/xyz/_workitems/edit/10",
},
{
description: "IsLinkPresent: valid task link 9",
msg: "https://dev.azure.com/abc/xyz/_workitems/edit/102/",
expectedData: []string{"https:", "", "dev.azure.com", "abc", "xyz", "_workitems", "edit", "102"},
isValid: true,
regex: constants.TaskLinkRegex,
expectedLink: "https://dev.azure.com/abc/xyz/_workitems/edit/102",
},
{
description: "IsLinkPresent: valid task link 10",
msg: "https://dev.azure.com/abc/xyz/_workitems/edit/102",
expectedData: []string{"https:", "", "dev.azure.com", "abc", "xyz", "_workitems", "edit", "102"},
isValid: true,
regex: constants.TaskLinkRegex,
expectedLink: "https://dev.azure.com/abc/xyz/_workitems/edit/102",
},
{
description: "IsLinkPresent: valid task link 11",
msg: "http://dev.azure.com/abc/xyz/_workitems/edit/102",
expectedData: []string{"http:", "", "dev.azure.com", "abc", "xyz", "_workitems", "edit", "102"},
isValid: true,
regex: constants.TaskLinkRegex,
expectedLink: "http://dev.azure.com/abc/xyz/_workitems/edit/102",
},
{
description: "IsLinkPresent: valid task link 12",
msg: "\n\nhttp://dev.azure.com/abc/xyz/_workitems/edit/102 mock-text",
expectedData: []string{"http:", "", "dev.azure.com", "abc", "xyz", "_workitems", "edit", "102"},
isValid: true,
regex: constants.TaskLinkRegex,
expectedLink: "http://dev.azure.com/abc/xyz/_workitems/edit/102",
},
{
description: "IsLinkPresent: invalid task link 1",
msg: "https://abc/xyz/_workitems/edit/1",
Expand Down

0 comments on commit 7d93631

Please sign in to comment.