You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Describe the bug
Getting a value from a collection after setting the entire collection returns 'undefined'
To Reproduce
See nodeJS script below.
Expected behaviour
Getting a value from a collection after setting the entire collection should return the correct/actual value, not undefined.
Versions (please complete the following information):
Environment: nodeJS v16.16.0
yaml: v2.2.1
Additional context
See script below.
// ----------------------------------------------------------------------------// Using: // - [email protected]// - nodeJS v16.16.0// // Bug: Getting a value from a collection after setting the entire collection// returns 'undefined'// // Summary of Steps:// 1. Parse a document with a Seq collection// 2. Get (getIn) the value of an entry in the Seq collection ... OK// 3. Set the entire collection using 'set' or 'setIn'// 4. Get (getIn) the value of an entry in the Seq collection again ... NOK (undefined)// ----------------------------------------------------------------------------const{ parseDocument }=require('yaml')constcontent=`---name: simulacrumpath: /opt/simulacrumsplunk: - log_path: /var/log/simulacrum/access.log index: apps_nonprod sourcetype: generic_singleline source: simulacrum-access - log_path: /var/log/simulacrum/error.log index: apps_nonprod sourcetype: _json source: simulacrum-error`// Parse the YAMLconstdoc=parseDocument(content)// Print it out ... GOOD!console.log(doc.toString())// Get the splunk/0/log_path valueletlogPath=doc.getIn(["splunk",0,"log_path"])// Print it out ... GOOD!console.log(`==> OK logPath: ${JSON.stringify(logPath)} <== OK`)// Use `set` or `setIn` to set the entire `splunk` collectionconstnewValue=[{log_path: "fish",index: "fry",sourcetype: "never",source: "more"}]// doc.set("splunk", newValue)doc.setIn(["splunk"],newValue)// Print it out ... GOOD!console.log(doc.toString())// Get the `splunk` sectionconstsplunk=doc.get("splunk")// Print it out ... GOODconsole.log(`splunk: ${JSON.stringify(splunk)}`)// Get the splunk/0/log_path value (same as above)logPath=doc.getIn(["splunk",0,"log_path"])// Print it out ... BAD! // The value of `logPath` is `undefined`// ...`logPath` should be `fish`console.log(`==> NOK logPath: ${JSON.stringify(logPath)} <== NOK, undefined`)
The text was updated successfully, but these errors were encountered:
This currently counts as intended behaviour. The get/set methods were added mostly as sugar for the direct access modification of the node tree, which supports having plain JS values embedded in it. This means that the setIn() doesn't apply doc.createNode() on the value that's set, and that getIn() doesn't navigate through non-node objects.
Changing the former would be a breaking change, but the I think the latter could be extended as a non-breaking change, along with #386.
Describe the bug
Getting a value from a collection after setting the entire collection returns 'undefined'
To Reproduce
See nodeJS script below.
Expected behaviour
Getting a value from a collection after setting the entire collection should return the correct/actual value, not undefined.
Versions (please complete the following information):
yaml
: v2.2.1Additional context
See script below.
The text was updated successfully, but these errors were encountered: