@@ -66,8 +66,8 @@ func (w *removingWalker) doList(t *schema.List) (errs ValidationErrors) {
6666 // Ignore error because we have already validated this list
6767 pe , _ := listItemToPathElement (w .allocator , w .schema , t , i , item )
6868 path , _ := fieldpath .MakePath (pe )
69- // save items that do have the path when we shouldExtract
70- // but ignore it when we are removing (i.e. !w.shouldExtract)
69+ // save items on the path when we shouldExtract
70+ // but ignore them when we are removing (i.e. !w.shouldExtract)
7171 if w .toRemove .Has (path ) {
7272 if w .shouldExtract {
7373 newItems = append (newItems , item .Unstructured ())
@@ -77,11 +77,13 @@ func (w *removingWalker) doList(t *schema.List) (errs ValidationErrors) {
7777 }
7878 if subset := w .toRemove .WithPrefix (pe ); ! subset .Empty () {
7979 item = removeItemsWithSchema (item , subset , w .schema , t .ElementType , w .shouldExtract )
80+ } else {
81+ // don't save items not on the path when we shouldExtract.
82+ if w .shouldExtract {
83+ continue
84+ }
8085 }
81- // save items that do not have the path only when removing (i.e. !w.shouldExtract)
82- if ! w .shouldExtract {
83- newItems = append (newItems , item .Unstructured ())
84- }
86+ newItems = append (newItems , item .Unstructured ())
8587 }
8688 if len (newItems ) > 0 {
8789 w .out = newItems
@@ -112,7 +114,8 @@ func (w *removingWalker) doMap(t *schema.Map) ValidationErrors {
112114 if ft , ok := fieldTypes [k ]; ok {
113115 fieldType = ft
114116 }
115- // save items on the path only when extracting.
117+ // save values on the path when we shouldExtract
118+ // but ignore them when we are removing (i.e. !w.shouldExtract)
116119 if w .toRemove .Has (path ) {
117120 if w .shouldExtract {
118121 newMap [k ] = val .Unstructured ()
@@ -122,7 +125,7 @@ func (w *removingWalker) doMap(t *schema.Map) ValidationErrors {
122125 if subset := w .toRemove .WithPrefix (pe ); ! subset .Empty () {
123126 val = removeItemsWithSchema (val , subset , w .schema , fieldType , w .shouldExtract )
124127 } else {
125- // don't save items not on the path when extracting .
128+ // don't save values not on the path when we shouldExtract .
126129 if w .shouldExtract {
127130 return true
128131 }
0 commit comments