Fix for #2677#2705
Conversation
| if stringValue == "<<" { | ||
| node.Tag = "!!merge" | ||
| } else { | ||
| node.Tag = "!!str" | ||
| } | ||
| return node |
There was a problem hiding this comment.
Could you add tests for this?
Because it's not really obvious
There was a problem hiding this comment.
Added a test that replicates what's documented in #2677, will look at doing a more targeted test that exercises just this functionality.
|
Changed the existing tests to pass given the changes in yaml/go-yaml#348, added a test for the given fix, and found a corner case to improve specific to the example with multiplication. I am still very new to both the It seems when Regarding |
|
@mikefarah @ingydotnet what do you think about what @W-Floyd explained ? Thanks I think his analysis is good, but it leads me to question the change we did in go-yaml with It might be OK, and then imply a change in yq like the one suggested here, but I prefer everyone to review the changes here and the one we did in go-yaml |
|
I'm very surprised by the commit That remove the merge and float tags in a lot of files. It doesn't sound OK. Maybe it's due to the fact the go-yaml PR needs to be merged first, but seeing such commit that changes so much things make me feel there is something wrong |
|
Yes, it is for the sake of yaml/go-yaml#348 - I can back out those changes if they should wait. But neither will the added test work until that's merged. |
| expression: `.a = .a % .b`, | ||
| expected: []string{ | ||
| "D0, P[], (!!map)::{a: !!float 2, b: 2.5}\n", | ||
| "D0, P[], (!!map)::{a: 2, b: 2.5}\n", |
There was a problem hiding this comment.
This seems to have change a whole bunch of unrelated things...
There was a problem hiding this comment.
Sorry, that's to match the new output of yaml/go-yaml#348 - I can revert it for now if we want to handle that separately.
There was a problem hiding this comment.
| description: "explode expands << merge keys regardless of explicit tag style (!!merge or plain)", | ||
| document: mixedMergeTagStyleDocument, | ||
| expression: `explode(.)`, | ||
| expected: []string{"D0, P[], (!!map)::" + mixedMergeTagStyleExplodedDocument}, |
There was a problem hiding this comment.
This test makes sense to me 👍🏼
| log.Debugf("going to applied assignment to LHS: %v with RHS: %v", NodeToString(lhs), NodeToString(candidate)) | ||
|
|
||
| if candidate.Tag == "!!merge" { | ||
| if candidate.Tag == "!!merge" && !candidate.IsMapKey { |
There was a problem hiding this comment.
been a long time since I've touched this logic...I'd be wary of making changes. Not sure why this is needed?
There was a problem hiding this comment.
I took more of a look, and believe this entire check is no longer required, due to DontFollowAlias: true. Removing it has the same result. I added a test to show what this accomplishes.
|
Testing by adding this to |
|
|
||
| log.Debugf("going to applied assignment to LHS: %v with RHS: %v", NodeToString(lhs), NodeToString(candidate)) | ||
|
|
||
| if candidate.Tag == "!!merge" { |
There was a problem hiding this comment.
Oh, got it, read your comment later in the PR
|
While I believe that yaml/go-yaml#348 is doing the "right" thing, It occurred to me later that the right thing doesn't necessarily mean the "same" thing as v3. I'll take a look and report back on that. |
Depends on yaml/go-yaml#348