Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,12 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).


## [5.4.2] - 2026-09-13

### Fixed
- `forceQuotes` no longer quotes non-string scalars, #798.


## [5.4.1] - 2026-08-26

### Changed
Expand Down Expand Up @@ -763,6 +769,7 @@ architectural improvements before moving forward.
- First public release


[5.4.2]: https://github.com/nodeca/js-yaml/compare/5.4.1...5.4.2
[5.4.1]: https://github.com/nodeca/js-yaml/compare/5.4.0...5.4.1
[5.4.0]: https://github.com/nodeca/js-yaml/compare/5.3.0...5.4.0
[5.3.0]: https://github.com/nodeca/js-yaml/compare/5.2.3...5.3.0
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "js-yaml",
"version": "5.4.1",
"version": "5.4.2",
"description": "YAML 1.2 parser and serializer",
"keywords": [
"yaml",
Expand Down
4 changes: 3 additions & 1 deletion src/ast/styler_defaults.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,10 @@ function doubleQuoteWhitespaceOnly (layout: ScalarLayout): void {
function applyForceQuotesOption (layout: ScalarLayout): void {
if (!layout.presenterOptions.forceQuotes) return

// forceQuotes applies only to plain values, not to mapping keys.
// forceQuotes applies only to plain string values, not to mapping keys
// or other types.
if (layout.isKey || layout.style !== SCALAR_STYLE.PLAIN) return
if (layout.node.tag !== layout.presenterOptions.schema.defaultScalarTag.tagName) return

layout.style = layout.node.value.includes('\n')
? SCALAR_STYLE.DOUBLE_QUOTED
Expand Down
8 changes: 7 additions & 1 deletion test/core/units/dump-options.test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,13 @@ describe('dump options', () => {
})

it('forceQuotes — quotes non-key strings using quoteStyle', () => {
assert.equal(dump({ hello: 'world' }, { forceQuotes: true }), "hello: 'world'\n")
assert.equal(
dump(
{ hello: 'world', b: true, i: 42, f: 3.14, nil: null, d: new Date(0) },
{ forceQuotes: true }
),
"hello: 'world'\nb: true\ni: 42\nf: 3.14\nnil: null\nd: 1970-01-01T00:00:00.000Z\n"
)
assert.equal(
dump({ hello: 'world' }, { forceQuotes: true, quoteStyle: 'double' }),
'hello: "world"\n'
Expand Down
Loading