Skip to content

Commit

Permalink
Merge pull request #802 from inteon/fix_marker_parsing
Browse files Browse the repository at this point in the history
🐛 Fix marker parsing
  • Loading branch information
k8s-ci-robot committed Apr 26, 2023
2 parents 6a6b7b8 + d5db06c commit 65c0c2c
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
8 changes: 8 additions & 0 deletions pkg/markers/parse.go
Original file line number Diff line number Diff line change
Expand Up @@ -373,6 +373,14 @@ func guessType(scanner *sc.Scanner, raw string, allowSlice bool) *Argument {

// parseString parses either of the two accepted string forms (quoted, or bare tokens).
func (a *Argument) parseString(scanner *sc.Scanner, raw string, out reflect.Value) {
// we need to temporarily disable the scanner's int/float parsing, since we want to
// prevent number parsing errors.
oldMode := scanner.Mode
scanner.Mode = oldMode &^ sc.ScanInts &^ sc.ScanFloats
defer func() {
scanner.Mode = oldMode
}()

// strings are a bit weird -- the "easy" case is quoted strings (tokenized as strings),
// the "hard" case (present for backwards compat) is a bare sequence of tokens that aren't
// a comma.
Expand Down
3 changes: 3 additions & 0 deletions pkg/markers/parse_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,9 @@ var _ = Describe("Parsing", func() {

Context("of individual arguments", func() {
It("should support bare strings", argParseTestCase{arg: Argument{Type: StringType}, raw: `some string here!`, output: "some string here!"}.Run)
It("should support bare strings containing number-ish values 1", argParseTestCase{arg: Argument{Type: StringType}, raw: `aa 0Baaa aaa`, output: "aa 0Baaa aaa"}.Run)
It("should support bare strings containing number-ish values 2", argParseTestCase{arg: Argument{Type: StringType}, raw: `/tmp/tmp-CHECKCRD-0B7LDeoZta`, output: "/tmp/tmp-CHECKCRD-0B7LDeoZta"}.Run)
It("should support bare strings containing number-ish values 3", argParseTestCase{arg: Argument{Type: StringType}, raw: `.0B7LDeoZt`, output: ".0B7LDeoZt"}.Run)
It("should support double-quoted strings", argParseTestCase{arg: Argument{Type: StringType}, raw: `"some; string, \nhere"`, output: "some; string, \nhere"}.Run)
It("should support raw strings", argParseTestCase{arg: Argument{Type: StringType}, raw: "`some; string, \\nhere`", output: `some; string, \nhere`}.Run)
It("should support integers", argParseTestCase{arg: Argument{Type: IntType}, raw: "42", output: 42}.Run)
Expand Down

0 comments on commit 65c0c2c

Please sign in to comment.