Skip to content

Commit

Permalink
path_util: Removing support for quoted strings
Browse files Browse the repository at this point in the history
  • Loading branch information
Lucas Hinderberger committed Jun 7, 2024
1 parent d3517d9 commit 9413bff
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 30 deletions.
13 changes: 1 addition & 12 deletions pkg/lib/util/path_util.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (

// pathSpecRegex validates and (via its capture groups) breaks up a
// path spec string in a single step (see ParsePathSpec).
var pathSpecRegex *regexp.Regexp = regexp.MustCompile(`^([0-9]*)@([^"]+)$`)
var pathSpecRegex *regexp.Regexp = regexp.MustCompile(`^([0-9]*)@(.+)$`)

// PathSpec is a path specifier for including tests within manifests.
type PathSpec struct {
Expand All @@ -24,17 +24,6 @@ type PathSpec struct {
// It returns a boolean result that indicates if parsing was successful
// (i.e. if s is a valid path specifier).
func ParsePathSpec(s string) (PathSpec, bool) {
// Remove outer quotes, if present
if len(s) >= 2 && s[0] == '"' {
if s[len(s)-1] != '"' {
// path spec must have matching quotes, if quotes are present
return PathSpec{}, false
}

s = s[1 : len(s)-1]
}

// Parse
matches := pathSpecRegex.FindStringSubmatch(s)
if matches == nil {
return PathSpec{}, false
Expand Down
19 changes: 1 addition & 18 deletions pkg/lib/util/path_util_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,21 +43,12 @@ func TestParsePathSpec(t *testing.T) {
require.True(t, ok)
require.Equal(t, testCase.expected, actual)
})

t.Run(testCase.s+" quoted", func(t *testing.T) {
s := `"` + testCase.s + `"`

actual, ok := ParsePathSpec(s)
require.True(t, ok)
require.Equal(t, testCase.expected, actual)
})
}
})

t.Run("invalid path specs are detected", func(t *testing.T) {
testCases := []string{
"", // empty
`"@foo.json`, `@foo.json"`, // superfluous quotes
"", // empty
`foo@bar.baz`, `1.23@foo.json`, // non-digit parallel runs
`p@old.syntax`, `p5@old.syntax`, `p123@old.syntax`, // old syntax
}
Expand All @@ -70,14 +61,6 @@ func TestParsePathSpec(t *testing.T) {
require.False(t, ok)
require.Zero(t, actual)
})

t.Run(s+" quoted", func(t *testing.T) {
sq := `"` + s + `"`

actual, ok := ParsePathSpec(sq)
require.False(t, ok)
require.Zero(t, actual)
})
}
})
}

0 comments on commit 9413bff

Please sign in to comment.