From e1936e33817e2413acadbb3db8e4e36df7e6e7a5 Mon Sep 17 00:00:00 2001 From: Tim Date: Tue, 3 Sep 2024 13:41:55 +0200 Subject: [PATCH] initial commit --- yaml/_dumper_state.ts | 12 ++++++------ yaml/stringify_test.ts | 1 + 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/yaml/_dumper_state.ts b/yaml/_dumper_state.ts index 615e39866404..cab813465e32 100644 --- a/yaml/_dumper_state.ts +++ b/yaml/_dumper_state.ts @@ -744,8 +744,12 @@ export class DumperState { if (block) { block = this.flowLevel < 0 || this.flowLevel > level; } - - if (isObject(value)) { + if (typeof value === "string" || value instanceof String) { + value = value instanceof String ? value.valueOf() : value; + if (tag !== "?") { + value = this.stringifyScalar(value as string, { level, isKey }); + } + } else if (isObject(value)) { const duplicateIndex = this.duplicates.indexOf(value); const duplicate = duplicateIndex !== -1; @@ -789,10 +793,6 @@ export class DumperState { } } } - } else if (typeof value === "string") { - if (tag !== "?") { - value = this.stringifyScalar(value, { level, isKey }); - } } else { if (this.skipInvalid) return null; throw new TypeError(`Cannot stringify ${typeof value}`); diff --git a/yaml/stringify_test.ts b/yaml/stringify_test.ts index 9aa35958be61..ed2efc963355 100644 --- a/yaml/stringify_test.ts +++ b/yaml/stringify_test.ts @@ -694,6 +694,7 @@ Oren: Ben-Kiki Deno.test("stringify() handles string", () => { assertEquals(stringify("Hello World"), "Hello World\n"); + assertEquals(stringify(new String("Hello World")), "Hello World\n"); }); Deno.test("stringify() uses quotes around deprecated boolean notations when `compatMode: true`", () => {