Skip to content

Commit

Permalink
no path url pattern should be invalid
Browse files Browse the repository at this point in the history
  • Loading branch information
karupanerura committed Jul 7, 2019
1 parent e5284df commit adc0f96
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
7 changes: 5 additions & 2 deletions host_path_matcher.go
Expand Up @@ -21,9 +21,12 @@ func (m *genericHostPathMatcher) MatchHostPath(host, path string) bool {

// CompileHostPathMatcher is constructor for HostPathMatcher
func CompileHostPathMatcher(pattern string) (HostPathMatcher, error) {
parts := strings.SplitN(pattern, "/", 2)
host, path := parts[0], parts[1]
index := strings.Index(pattern, "/")
if index == -1 {
return nil, fmt.Errorf("Invalid URL pattern: %s (No Path)", pattern)
}

host, path := pattern[:index], pattern[index+1:]
hostMatcher, err := compileHostMatcher(host)
if err != nil {
return nil, fmt.Errorf("Invalid URL pattern: %s (%s)", pattern, err.Error())
Expand Down
1 change: 1 addition & 0 deletions host_path_matcher_test.go
Expand Up @@ -82,6 +82,7 @@ func TestCompileHostPathMatcher(t *testing.T) {

t.Run("Invalid", func(t *testing.T) {
patterns := []string{
"hostnameonly",
"/service1/*/foo/*",
"*/service1/*/foo/*",
"*/service1/*/foo/",
Expand Down

0 comments on commit adc0f96

Please sign in to comment.