Skip to content

Commit 965cb76

Browse files
authored
Merge pull request #493 from gfrey/fix_fieldpath_parser
Fix infinite loop in fieldPath parser for single-letter field names
2 parents 7c7672f + f87c35d commit 965cb76

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed

Diff for: pkg/graph/fieldpath/parser.go

+1-2
Original file line numberDiff line numberDiff line change
@@ -73,8 +73,7 @@ func (p *parser) parse() ([]Segment, error) {
7373
return nil, err
7474
}
7575
segments = append(segments, Segment{Name: field, Index: -1})
76-
77-
} else if p.pos+1 < p.len && p.input[p.pos] != '[' {
76+
} else if p.pos < p.len && p.input[p.pos] != '[' {
7877
// Parse unquoted field until we hit a [ or .
7978
field, err := p.parseUnquotedField()
8079
if err != nil {

Diff for: pkg/graph/fieldpath/parser_test.go

+8
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,14 @@ func TestParse(t *testing.T) {
2525
want []Segment
2626
wantErr bool
2727
}{
28+
{
29+
name: "simple single letter path",
30+
path: "data.A",
31+
want: []Segment{
32+
{Name: "data", Index: -1},
33+
{Name: "A", Index: -1},
34+
},
35+
},
2836
{
2937
name: "simple path",
3038
path: "spec.containers",

0 commit comments

Comments
 (0)