From 395854ae0611fdd2c9bee14f942b2725469bd8af Mon Sep 17 00:00:00 2001 From: Oleg Olivson Date: Fri, 24 Jan 2025 14:39:47 +0100 Subject: [PATCH] fix: fixed nested values in 'fields' query parameter --- node/path_matcher.go | 5 +++++ node/path_matcher_test.go | 5 +++++ 2 files changed, 10 insertions(+) diff --git a/node/path_matcher.go b/node/path_matcher.go index b8d20ca..8416a9c 100644 --- a/node/path_matcher.go +++ b/node/path_matcher.go @@ -195,6 +195,11 @@ func (e *PathMatchExpression) match(segs segments, base *Path, candidate *Path) // we keep peeling back slice as long as it continues to match candidate as we // peel that back as well. + if j < i { + // segments path is longer than candidate, we need to traverse segments to only verify common part + i-- + continue + } if j == i { if p.Meta.Ident() != segs[i] { return false diff --git a/node/path_matcher_test.go b/node/path_matcher_test.go index ab27f02..5cdc496 100644 --- a/node/path_matcher_test.go +++ b/node/path_matcher_test.go @@ -124,4 +124,9 @@ module m { p4, _ := parseUrlPath("ddd/eee", module) fc.AssertEqual(t, false, expr.PathMatches(p4[0].Parent, p4[len(p4)-1])) + + // Match parent when path targets child nodes + expr2, err := ParsePathExpression("aaa/bbb/ccc") + fc.AssertEqual(t, nil, err) + fc.AssertEqual(t, true, expr2.PathMatches(p1[0].Parent, p1[len(p1)-1])) }