@@ -14,7 +14,7 @@ import (
14
14
)
15
15
16
16
// PathMatcher returns all RNodes matching the path wrapped in a SequenceNode.
17
- // Lists may have multiple elements matching the path, and each matching element
17
+ // Lists may have multiple elements matching the pafunc cleanPath( path []string) []string {g element
18
18
// is added to the return result.
19
19
// If Path points to a SequenceNode, the SequenceNode is wrapped in another SequenceNode
20
20
// If Path does not contain any lists, the result is still wrapped in a SequenceNode of len == 1
@@ -138,12 +138,6 @@ func (p *PathMatcher) doField(rn *RNode) (*RNode, error) {
138
138
// lookup the field
139
139
field , err := rn .Pipe (Get (p .Path [0 ]))
140
140
if err != nil {
141
- // check error is an invalid kind error
142
- invalidKindErr := & InvalidNodeKindError {}
143
- if errors .As (err , & invalidKindErr ) {
144
- // if the field is valid json or yaml, continue to lookup the next part of the path
145
- fmt .Print ("-----------------------------\n OUTPUT: " , err )
146
- }
147
141
return nil , err
148
142
}
149
143
@@ -347,25 +341,6 @@ func cleanPath(path []string) []string {
347
341
return p
348
342
}
349
343
350
- // structuredDataNode is a wrapper around RNode that handles serialization back to scalar fields
351
- // when the underlying structured data is modified
352
- type structuredDataNode struct {
353
- RNode
354
- structuredRoot * RNode // The root of the structured data
355
- scalarField * RNode // The original scalar field containing the structured data
356
- }
357
-
358
- // Override SetYNode to handle structured data serialization
359
- func (s * structuredDataNode ) SetYNode (node * yaml.Node ) {
360
- // Call the original SetYNode
361
- s .RNode .SetYNode (node )
362
-
363
- // Serialize the modified structured data back to the scalar field
364
- if modifiedData , err := s .structuredRoot .String (); err == nil {
365
- s .scalarField .YNode ().Value = strings .TrimSpace (modifiedData )
366
- }
367
- }
368
-
369
344
// handleStructuredDataInScalar processes a scalar field that contains structured data (JSON/YAML)
370
345
// and allows path navigation within that structured data
371
346
func (p * PathMatcher ) handleStructuredDataInScalar (scalarField * RNode ) (* RNode , error ) {
@@ -386,29 +361,5 @@ func (p *PathMatcher) handleStructuredDataInScalar(scalarField *RNode) (*RNode,
386
361
}
387
362
p .Matches = pm .Matches
388
363
389
- // For structured data, we need to create a special result node that knows how to
390
- // serialize back to the original scalar when modified
391
- if result != nil && len (result .YNode ().Content ) > 0 {
392
- // Wrap the result with structured data context
393
- for _ , node := range result .YNode ().Content {
394
- wrappedNode := NewRNode (node )
395
- // Add a custom method to handle setting values back to structured data
396
- wrappedNode = p .wrapWithStructuredDataHandler (wrappedNode , structuredField , scalarField )
397
- result .YNode ().Content [0 ] = wrappedNode .YNode ()
398
- }
399
- }
400
-
401
364
return result , nil
402
365
}
403
-
404
- // wrapWithStructuredDataHandler creates a wrapper that will serialize structured data back
405
- // to the scalar field when the node is modified
406
- func (p * PathMatcher ) wrapWithStructuredDataHandler (targetNode , structuredRoot , scalarField * RNode ) * RNode {
407
- // Create a custom node that overrides SetYNode to handle structured data serialization
408
- wrapper := & structuredDataNode {
409
- RNode : * targetNode ,
410
- structuredRoot : structuredRoot ,
411
- scalarField : scalarField ,
412
- }
413
- return & wrapper .RNode
414
- }
0 commit comments