@@ -84,22 +84,24 @@ func (w *removingWalker) doList(t *schema.List) (errs ValidationErrors) {
8484 path , _ := fieldpath .MakePath (pe )
8585 // save items on the path when we shouldExtract
8686 // but ignore them when we are removing (i.e. !w.shouldExtract)
87- if w .toRemove .Has (path ) {
88- if w .shouldExtract {
89- newItems = append (newItems , removeItemsWithSchema (item , w .toRemove , w .schema , t .ElementType , w .shouldExtract ).Unstructured ())
90- } else {
91- continue
87+ isExactPathMatch := w .toRemove .Has (path )
88+ isPrefixMatch := ! w .toRemove .WithPrefix (pe ).Empty ()
89+ if w .shouldExtract {
90+ if isPrefixMatch {
91+ item = removeItemsWithSchema (item , w .toRemove .WithPrefix (pe ), w .schema , t .ElementType , w .shouldExtract )
92+ }
93+ if isExactPathMatch || isPrefixMatch {
94+ newItems = append (newItems , item .Unstructured ())
9295 }
93- }
94- if subset := w .toRemove .WithPrefix (pe ); ! subset .Empty () {
95- item = removeItemsWithSchema (item , subset , w .schema , t .ElementType , w .shouldExtract )
9696 } else {
97- // don't save items not on the path when we shouldExtract.
98- if w .shouldExtract {
97+ if isExactPathMatch {
9998 continue
10099 }
100+ if isPrefixMatch {
101+ item = removeItemsWithSchema (item , w .toRemove .WithPrefix (pe ), w .schema , t .ElementType , w .shouldExtract )
102+ }
103+ newItems = append (newItems , item .Unstructured ())
101104 }
102- newItems = append (newItems , item .Unstructured ())
103105 }
104106 if len (newItems ) > 0 {
105107 w .out = newItems
0 commit comments