-
-
Notifications
You must be signed in to change notification settings - Fork 134
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
replacing values with a multi-line string value provides broken yaml format. #447
Comments
Also reported two years ago without any resolution. :( |
I'm attempting to see if I can fix this. |
Reproduced the issue in {
path: "$.data.value1",
dst: `
data:
value1: orig1
value2: orig2
`,
src: `
line1
line2
`,
expected: `
data:
value1: |-
line1
line2
value2: orig2
`,
}, I'll attempt to fix the problem. |
The AST node replace doesn't care how deep it is so it plain does a replace on the node value resulting in a YAML that doesn't work. |
Tomorrow I'll try to fix this. I have an idea of tracking the deepness recursively for StringNodes for multi-line text. let's see.. |
so I figured out that the library just expects you to pass in the value you require including the right indentation level. {
path: "$.data.value1.orig1",
dst: `
data:
value1:
orig1: orig1.1
value2: orig2
`,
src: `|-
line1
line2
`,
expected: `
data:
value1:
orig1: |-
line1
line2
value2: orig2
`,
}, Passes as a test case. |
Nice find @Skarlso |
Do you have an example? |
I tried replacing objects, but the marshalling is all over the place. There is virtually no consistency in indentation whatsoever. I can't find a pattern or anything that would make it work. :( |
Okay, this now worked finally: {
path: "$.data.value1.orig1",
dst: `
data:
value1:
orig1: orig1.1
value2: orig2
`,
src: `
orig1:
newValue:
- value1
- value2
`,
expected: `
data:
value1:
orig1:
orig1:
newValue:
- value1
- value2
value2: orig2
`,
}, |
Describe the bug
The multi line string is replaced, but the indentation of the string lines is wrong.
To Reproduce
use yaml document:
replace
$.data.value1
byThe result will be
instead of
The data is parsed with
parser.ParseBytes(data, 0)
.The replace operation is
Expected behavior
provide correct multi-line result
Screenshots
If applicable, add screenshots to help explain your problem.
Version Variables
Additional context
The ast nodes provide some strange column values for string value. Especially there is no column info for
follow-up value lines. Therefore, the
String()
method just uses the original string formatting from thetarget value, which will for sure be wrong in most cases. When replacing a value, only the column value is adapted for the new value, but this cannot be used to serialize follow-up lines.
The text was updated successfully, but these errors were encountered: