Skip to content

Refactor YAML handling to improve quoting logic and add support for multiline strings#18298

Merged
cptpiepmatz merged 2 commits into
nushell:mainfrom
fdncred:fix_yaml_bugs_20260528
May 28, 2026
Merged

Refactor YAML handling to improve quoting logic and add support for multiline strings#18298
cptpiepmatz merged 2 commits into
nushell:mainfrom
fdncred:fix_yaml_bugs_20260528

Conversation

@fdncred

@fdncred fdncred commented May 28, 2026

Copy link
Copy Markdown
Contributor

Description

This PR updates to yaml / to yml to emit YAML that is closer to YAML 1.2 plain-scalar rules while still preserving string semantics when quoting is required.

The main change is that string values are no longer quoted by default. Instead, the emitter now only quotes scalars when quoting is necessary for correctness. In addition, multiline strings are emitted as YAML literal block scalars with correct chomping behavior.

User-facing changes (Release notes)

More idiomatic YAML output with smarter string quoting

The previous emitter always quoted string values, which produced valid YAML but was more conservative than necessary and less aligned with YAML 1.2 plain-scalar rules.

This change makes output:

  • more readable
  • closer to idiomatic YAML
  • more spec-aligned for plain scalars
  • still safe for roundtripping by quoting values that would otherwise be reinterpreted as non-strings

Before:

value: 'off'
path: '/dev/stdout'
listen: '0.0.0.0:8444,0.0.0.0:8445 ssl'
name: 'kong'
kind: 'Deployment'

After:

value: 'off'
path: /dev/stdout
listen: 0.0.0.0:8444,0.0.0.0:8445 ssl
name: kong
kind: Deployment

Multiline strings now emit as:

string: |-
  Hello
  world

Additional notes

Examples from #18010 and #16072 were used for testing and creating new tests.

@fdncred fdncred added notes:fixes Noted in "Bug fixes" section notes:ready Indicates Ready for Release notes labels May 28, 2026

@cptpiepmatz cptpiepmatz left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overall this looks very reasonable

Comment thread crates/nu-command/src/formats/to/yaml.rs Outdated
Comment thread crates/nu-command/src/formats/to/yaml.rs Outdated
@cptpiepmatz cptpiepmatz merged commit 7a09631 into nushell:main May 28, 2026
17 checks passed
@github-actions github-actions Bot added this to the v0.114.0 milestone May 28, 2026
@fdncred fdncred deleted the fix_yaml_bugs_20260528 branch May 28, 2026 21:00
@cptpiepmatz cptpiepmatz added notes:other Noted in "Other changes" section and removed notes:fixes Noted in "Bug fixes" section labels May 29, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

notes:other Noted in "Other changes" section notes:ready Indicates Ready for Release notes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants