Skip to content

Commit bd16385

Browse files
fix
1 parent a72bd09 commit bd16385

File tree

2 files changed

+28
-7
lines changed

2 files changed

+28
-7
lines changed

arazzo/criterion/condition.go

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -56,13 +56,8 @@ func newCondition(rawCondition string) (*Condition, error) {
5656

5757
// String literal value handling (single and double quotes) until parsing is tokenized.
5858
// Reference: https://spec.openapis.org/arazzo/v1.0.0#literals
59-
if len(parts) > 3 && strings.HasPrefix(parts[2], "'") && strings.HasSuffix(parts[len(parts)-1], "'") {
60-
parts[2] = strings.Join(parts[2:], " ")
61-
parts = parts[:3]
62-
} else if len(parts) > 3 && strings.HasPrefix(parts[2], "\"") && strings.HasSuffix(parts[len(parts)-1], "\"") {
63-
parts[2] = strings.Join(parts[2:], " ")
64-
parts = parts[:3]
65-
}
59+
parts = handleQuotedString(parts, "'")
60+
parts = handleQuotedString(parts, "\"")
6661

6762
if len(parts) > 3 {
6863
// TODO this is a complex condition that we don't currently support
@@ -120,3 +115,13 @@ func (s *Condition) Validate(line, column int, opts ...validation.Option) []erro
120115

121116
return errs
122117
}
118+
119+
// handleQuotedString processes parts that contain quoted strings (either single or double quotes)
120+
// and joins them into a single part if necessary.
121+
func handleQuotedString(parts []string, quoteChar string) []string {
122+
if len(parts) > 3 && strings.HasPrefix(parts[2], quoteChar) && strings.HasSuffix(parts[len(parts)-1], quoteChar) {
123+
parts[2] = strings.Join(parts[2:], " ")
124+
return parts[:3]
125+
}
126+
return parts
127+
}

arazzo/criterion/condition_test.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,22 @@ func TestNewCondition(t *testing.T) {
5454
Value: `"string literal with spaces"`,
5555
},
5656
},
57+
`$response.body#/test == "string with 'nested' quotes"`: {
58+
raw: `$response.body#/test == "string with 'nested' quotes"`,
59+
expected: &Condition{
60+
Expression: expression.Expression("$response.body#/test"),
61+
Operator: OperatorEQ,
62+
Value: `"string with 'nested' quotes"`,
63+
},
64+
},
65+
`$response.body#/test == 'string with "nested" quotes'`: {
66+
raw: `$response.body#/test == 'string with "nested" quotes'`,
67+
expected: &Condition{
68+
Expression: expression.Expression("$response.body#/test"),
69+
Operator: OperatorEQ,
70+
Value: `'string with "nested" quotes'`,
71+
},
72+
},
5773
}
5874

5975
for name, tt := range tests {

0 commit comments

Comments
 (0)