Skip to content

Commit

Permalink
Disallow @ character in URL patterns, so that people don't mistakenly…
Browse files Browse the repository at this point in the history
… try

to add URL patterns of the form username@hostname/path.
  • Loading branch information
Jim Minter committed Sep 11, 2017
1 parent a9e391d commit ae22665
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
2 changes: 1 addition & 1 deletion pkg/util/urlpattern/urlpattern.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ var InvalidPatternError = errors.New("invalid pattern")

var urlPatternRegex = regexp.MustCompile(`^` +
`(?:(\*|git|http|https|ssh)://)` +
`(\*|(?:\*\.)?[^/*]+)` +
`(\*|(?:\*\.)?[^@/*]+)` +
`(/.*)` +
`$`)

Expand Down
10 changes: 7 additions & 3 deletions pkg/util/urlpattern/urlpattern_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ func TestMatchPattern(t *testing.T) {
expectedScheme: `^(git|http|https|ssh)$`,
expectedHost: `^.*$`,
expectedPath: `^/.*$`,
expectedMatch: []string{`https://github.com/`},
expectedMatch: []string{`https://github.com/`, `https://user:password@github.com/`, `ssh://git@github.com/`},
expectedNotMatch: []string{`ftp://github.com/`},
},
{
Expand Down Expand Up @@ -80,15 +80,15 @@ func TestMatchPattern(t *testing.T) {
expectedScheme: `^https$`,
expectedHost: `^github\.com$`,
expectedPath: `^/.*$`,
expectedMatch: []string{`https://github.com/`},
expectedMatch: []string{`https://github.com/`, `https://user:password@github.com/`},
expectedNotMatch: []string{`https://test.github.com/`},
},
{
pattern: `https://*.git.luolix.top/*`,
expectedScheme: `^https$`,
expectedHost: `^(?:.*\.)?github\.com$`,
expectedPath: `^/.*$`,
expectedMatch: []string{`https://github.com/`, `https://test.github.com/`},
expectedMatch: []string{`https://github.com/`, `https://user:password@github.com/`, `https://test.github.com/`},
},
{
pattern: `https://\.+?()|[]{}^$/*`,
Expand All @@ -108,6 +108,10 @@ func TestMatchPattern(t *testing.T) {
pattern: `https://git*hub.com/*`,
expectedErr: true,
},
{
pattern: `*://git@github.com/*`,
expectedErr: true,
},
{
pattern: `https://github.com/`,
expectedScheme: `^https$`,
Expand Down

0 comments on commit ae22665

Please sign in to comment.