Merge pull request #93408 from joelsmith/master

jsonpath: disallow multiple immediate recursive descent

Kubernetes-commit: c0ec2eee41794796dee230f75478602b707f2be2
This commit is contained in:
Kubernetes Publisher 2020-08-02 04:21:40 -07:00
commit 00dbcca6ee
3 changed files with 7 additions and 1 deletions

View File

@ -263,6 +263,8 @@ func TestStructInput(t *testing.T) {
{"allarray", "{.Book[*].Author}", storeData, "Nigel Rees Evelyn Waugh Herman Melville", false},
{"allfields", `{range .Bicycle[*]}{ "{" }{ @.* }{ "} " }{end}`, storeData, "{red 19.95 true} {green 20.01 false} ", false},
{"recurfields", "{..Price}", storeData, "8.95 12.99 8.99 19.95 20.01", false},
{"recurdotfields", "{...Price}", storeData, "8.95 12.99 8.99 19.95 20.01", false},
{"superrecurfields", "{............................................................Price}", storeData, "", true},
{"allstructsSlice", "{.Bicycle}", storeData,
`[{"Color":"red","Price":19.95,"IsNew":true},{"Color":"green","Price":20.01,"IsNew":false}]`, false},
{"allstructs", `{range .Bicycle[*]}{ @ }{ " " }{end}`, storeData,

View File

@ -214,8 +214,11 @@ func (p *Parser) parseIdentifier(cur *ListNode) error {
return p.parseInsideAction(cur)
}
// parseRecursive scans the recursive desent operator ..
// parseRecursive scans the recursive descent operator ..
func (p *Parser) parseRecursive(cur *ListNode) error {
if lastIndex := len(cur.Nodes) - 1; lastIndex >= 0 && cur.Nodes[lastIndex].Type() == NodeRecursive {
return fmt.Errorf("invalid multiple recursive descent")
}
p.pos += len("..")
p.consumeText()
cur.append(newRecursive())

View File

@ -141,6 +141,7 @@ func TestFailParser(t *testing.T) {
{"invalid number", "{+12.3.0}", "cannot parse number +12.3.0"},
{"unterminated array", "{[1}", "unterminated array"},
{"unterminated filter", "{[?(.price]}", "unterminated filter"},
{"invalid multiple recursive descent", "{........}", "invalid multiple recursive descent"},
}
for _, test := range failParserTests {
_, err := Parse(test.name, test.text)