fix(yaml): handle string instances (#5897)

initial commit
This commit is contained in:
Tim Reichen 2024-09-04 01:28:55 +02:00 committed by GitHub
parent df562b1d28
commit 6c684b8bc8
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 7 additions and 6 deletions

View File

@ -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}`);

View File

@ -753,6 +753,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`", () => {