Skip to content

Commit

Permalink
fix: preserve escape codes in repo url of git webhook payload (argopr…
Browse files Browse the repository at this point in the history
…oj#17376)

Signed-off-by: Eric Bissonnette <ebisso.dev@gmail.com>
Signed-off-by: Mangaal <angommeeteimangaal@gmail.com>
  • Loading branch information
ebisso authored and Mangaal committed Mar 14, 2024
1 parent 2b6e389 commit 845a8c0
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 1 deletion.
2 changes: 1 addition & 1 deletion util/webhook/webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -321,7 +321,7 @@ func getWebUrlRegex(webURL string) (*regexp.Regexp, error) {
}

regexEscapedHostname := regexp.QuoteMeta(urlObj.Hostname())
regexEscapedPath := regexp.QuoteMeta(urlObj.Path[1:])
regexEscapedPath := regexp.QuoteMeta(urlObj.EscapedPath()[1:])
regexpStr := fmt.Sprintf(`(?i)^(http://|https://|%s@|ssh://(%s@)?)%s(:[0-9]+|)[:/]%s(\.git)?$`,
usernameRegex, usernameRegex, regexEscapedHostname, regexEscapedPath)
repoRegexp, err := regexp.Compile(regexpStr)
Expand Down
1 change: 1 addition & 0 deletions util/webhook/webhook_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -670,6 +670,7 @@ func Test_getWebUrlRegex(t *testing.T) {
{true, "https://example.com/org/repo", "ssh://user-name@example.com/org/repo", "valid usernames with hyphens in repo should match"},
{false, "https://example.com/org/repo", "ssh://-user-name@example.com/org/repo", "invalid usernames with hyphens in repo should not match"},
{true, "https://example.com:443/org/repo", "GIT@EXAMPLE.COM:22:ORG/REPO", "matches aren't case-sensitive"},
{true, "https://example.com/org/repo%20", "https://example.com/org/repo%20", "escape codes in path are preserved"},
}
for _, testCase := range tests {
testCopy := testCase
Expand Down

0 comments on commit 845a8c0

Please sign in to comment.