From 6d8adb41c1a8c4a45cb8597ffb149b8842b3a26b Mon Sep 17 00:00:00 2001 From: Vitaly Puzrin Date: Sun, 13 Sep 2026 02:59:04 +0300 Subject: [PATCH 1/2] Fix `forceQuotes` quoting non-string scalars, #798 --- src/ast/styler_defaults.ts | 4 +++- test/core/units/dump-options.test.mjs | 8 +++++++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/src/ast/styler_defaults.ts b/src/ast/styler_defaults.ts index d61ce640..26afb995 100644 --- a/src/ast/styler_defaults.ts +++ b/src/ast/styler_defaults.ts @@ -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 diff --git a/test/core/units/dump-options.test.mjs b/test/core/units/dump-options.test.mjs index 71aa3366..aa0abdaa 100644 --- a/test/core/units/dump-options.test.mjs +++ b/test/core/units/dump-options.test.mjs @@ -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' From 494400bd45cad078123cfc057e674a9a0a8d9983 Mon Sep 17 00:00:00 2001 From: Vitaly Puzrin Date: Sun, 13 Sep 2026 03:07:34 +0300 Subject: [PATCH 2/2] 5.4.2 released --- CHANGELOG.md | 7 +++++++ package.json | 2 +- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index f7e99590..0e7f1d79 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 @@ -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 diff --git a/package.json b/package.json index 10c360ff..30e6e86a 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "js-yaml", - "version": "5.4.1", + "version": "5.4.2", "description": "YAML 1.2 parser and serializer", "keywords": [ "yaml",