From 7d93631fea33e8c9bf32ed1c64317fa5148973c5 Mon Sep 17 00:00:00 2001 From: Lucas dos Santos Abreu Date: Tue, 27 Feb 2024 23:34:28 -0300 Subject: [PATCH] fix: should allow 0 in the middle to end (#160) * fix: should allow 0 in the middle to end * feat: tests with 0 in the middle --- server/constants/constants.go | 2 +- server/plugin/plugin_test.go | 64 +++++++++++++++++++++++++++++++++++ 2 files changed, 65 insertions(+), 1 deletion(-) diff --git a/server/constants/constants.go b/server/constants/constants.go index 7ffa2fcc..b1da4bc1 100644 --- a/server/constants/constants.go +++ b/server/constants/constants.go @@ -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]+` diff --git a/server/plugin/plugin_test.go b/server/plugin/plugin_test.go index 58c57427..a282f111 100644 --- a/server/plugin/plugin_test.go +++ b/server/plugin/plugin_test.go @@ -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",