Empty line added for end hierarchy key after #590 fix
Describe the bug #590 fix seems to have broken spacing behavior for end hierarchy keys with no values. In this case spaceBefore attribute becomes true and adds an empty line.
To Reproduce
#comment: This is comment in YAML file
userName: <--- this is correct
#comment: This is comment in YAML file (end hierarchy)
password:
+(extra empty line added) <---- unexpected
Expected behaviour Keys at the end of hierarchy should be parsed without adding extra line, maintaining the original spacing behavior.
Additional context
I traced this issue and found that if we remove
indicator !== 'seq-item-ind'
which was added as a part of #590 fix then extra line issue was resolved in my use case.
Please provide your thoughts on this
Could you provide an actual reproduction here? As in, a sequence of JS calls that produce the output that you think is wrong.
Hey there,
I just used below code to reproduce the issue with YAML.
const YAML = require('./dist')
const fs = require('fs')
const src = `app-secrets:
ingress:
# Description: Base64-encoded TLS certificate in one line without any carriage returns or line wrap.
tlsCertificate:
# Description: Keystore password for enabling backend TLS communication
keystorePassword:
clients:
# Description: Service account password for connecting to external reporting services.
reportingServicePassword: example_password_123
# Description: Application preference settings password.
applicationPreferencePassword: "SamplePassword@2024"
`
const doc = YAML.parseDocument(src)
const out = String(doc)
fs.writeFileSync('output.yaml', doc.toString(), 'utf8')
When you run this code, you will see a new line is added just after empty end hierarchy.
For your reference, I added screenshot as well.
Additionally, I already mentioned that to resolve this issue I have removed condition
indicator !== 'seq-item-ind' (newline case)
from resolveProps.js which was added as a fix for #590
Hi @eemeli , any update on this?
No updates here; have been focused on other work. It looks like these are minimal examples of the bug:
parseDocument('a:\n b:\n\nc:').toString() // 'a:\n b:\n\n\nc:\n'
parseDocument('- a:\n\n- b').toString() // '- a:\n\n\n- b\n'
where an empty line after a mapping inside a collection with an empty last value gets serialised as two empty lines.
It's probably a matter of the wrong node getting assigned spaceBefore: true, not sure why.
A fix to this would be welcome; not sure when I'm likely to have the time to look into this.