From 7e383c52ea7123a16cab9401f8bac7ab6c243ef6 Mon Sep 17 00:00:00 2001 From: Elad Ossadon Date: Sat, 26 Mar 2022 10:19:08 -0700 Subject: [PATCH 1/5] Fix Yaml/Syml stringify with keys longer than 1024 chars --- packages/yarnpkg-parsers/sources/syml.ts | 20 +++++++++++++++----- packages/yarnpkg-parsers/tests/syml.test.js | 18 +++++++++++++++--- 2 files changed, 30 insertions(+), 8 deletions(-) diff --git a/packages/yarnpkg-parsers/sources/syml.ts b/packages/yarnpkg-parsers/sources/syml.ts index 498df852d869..1cb24d0a52ef 100644 --- a/packages/yarnpkg-parsers/sources/syml.ts +++ b/packages/yarnpkg-parsers/sources/syml.ts @@ -91,11 +91,21 @@ function stringifyValue(value: any, indentLevel: number, newLineIfObject: boolea ? indent : ``; - if (stringifiedValue.startsWith(`\n`)) { - return `${recordIndentation}${stringifiedKey}:${stringifiedValue}`; - } else { - return `${recordIndentation}${stringifiedKey}: ${stringifiedValue}`; - } + + let keyPart: string; + let valuePart: string; + + // Yaml 1.2 spec says that keys over 1024 characters need to be prefixed with ? and the : goes in a new line + if (stringifiedKey.length > 1024) + keyPart = `? ${stringifiedKey}\n:`; + else keyPart = `${stringifiedKey}:`; + + if (stringifiedValue.startsWith(`\n`)) + valuePart = stringifiedValue; + else valuePart = ` ${stringifiedValue}`; + + + return `${recordIndentation}${keyPart}${valuePart}`; }).join(indentLevel === 0 ? `\n` : ``) || `\n`; if (!newLineIfObject) { diff --git a/packages/yarnpkg-parsers/tests/syml.test.js b/packages/yarnpkg-parsers/tests/syml.test.js index 259e8413b7b3..f1a307c369ae 100644 --- a/packages/yarnpkg-parsers/tests/syml.test.js +++ b/packages/yarnpkg-parsers/tests/syml.test.js @@ -1,4 +1,4 @@ -import {parseSyml} from '@yarnpkg/parsers'; +import {parseSyml, stringifySyml} from '@yarnpkg/parsers'; describe(`Syml parser`, () => { it(`shouldn't confuse old-style values with new-style keys`, () => { @@ -21,13 +21,25 @@ describe(`Syml parser`, () => { it(`should merge duplicates`, () => { expect( - parseSyml(` + parseSyml(` "lodash@npm:^4.17.20": version: 4.17.20 - + "lodash@npm:^4.17.20": version: 4.17.20 `), ).toEqual({'lodash@npm:^4.17.20': {version: `4.17.20`}}); }); }); + +describe(`Syml stringifyer`, () => { + it(`stringifies an object`, () => { + expect(stringifySyml({foo: {bar: `true`, baz: `quux`}})).toEqual(`foo:\n bar: true\n baz: quux\n`); + }); + + it(`stringifies an object with a long key with yaml 1.2 spec`, () => { + const longKey = `a`.repeat(1025); // long key is a string of length > 1024 + expect(stringifySyml({[longKey]: {bar: `true`, baz: `quux`}})).toEqual(`? ${longKey}\n:\n bar: true\n baz: quux\n`); + expect(stringifySyml({[longKey]: {[longKey]: `quux`, baz: `quux`}})).toEqual(`? ${longKey}\n:\n ? ${longKey}\n: quux\n baz: quux\n`); + }); +}); From 2f0ed391c7f614d3422e31cef832cc9b0ea45803 Mon Sep 17 00:00:00 2001 From: Elad Ossadon Date: Sat, 26 Mar 2022 10:31:27 -0700 Subject: [PATCH 2/5] yarn version check --- .yarn/versions/7041d864.yml | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 .yarn/versions/7041d864.yml diff --git a/.yarn/versions/7041d864.yml b/.yarn/versions/7041d864.yml new file mode 100644 index 000000000000..fe14fd26bb1f --- /dev/null +++ b/.yarn/versions/7041d864.yml @@ -0,0 +1,33 @@ +releases: + "@yarnpkg/builder": patch + "@yarnpkg/cli": patch + "@yarnpkg/core": patch + "@yarnpkg/doctor": patch + "@yarnpkg/nm": patch + "@yarnpkg/parsers": patch + "@yarnpkg/plugin-compat": patch + "@yarnpkg/plugin-constraints": patch + "@yarnpkg/plugin-dlx": patch + "@yarnpkg/plugin-essentials": patch + "@yarnpkg/plugin-exec": patch + "@yarnpkg/plugin-file": patch + "@yarnpkg/plugin-git": patch + "@yarnpkg/plugin-github": patch + "@yarnpkg/plugin-http": patch + "@yarnpkg/plugin-init": patch + "@yarnpkg/plugin-interactive-tools": patch + "@yarnpkg/plugin-link": patch + "@yarnpkg/plugin-nm": patch + "@yarnpkg/plugin-npm": patch + "@yarnpkg/plugin-npm-cli": patch + "@yarnpkg/plugin-pack": patch + "@yarnpkg/plugin-patch": patch + "@yarnpkg/plugin-pnp": patch + "@yarnpkg/plugin-pnpm": patch + "@yarnpkg/plugin-stage": patch + "@yarnpkg/plugin-typescript": patch + "@yarnpkg/plugin-version": patch + "@yarnpkg/plugin-workspace-tools": patch + "@yarnpkg/pnpify": patch + "@yarnpkg/sdks": patch + "@yarnpkg/shell": patch From 86971fc385ab14d0aea16268747d242066c86c2a Mon Sep 17 00:00:00 2001 From: Elad Ossadon Date: Sun, 27 Mar 2022 10:13:08 -0700 Subject: [PATCH 3/5] Update packages/yarnpkg-parsers/sources/syml.ts Co-authored-by: Trivikram Kamat <16024985+trivikr@users.noreply.github.com> --- packages/yarnpkg-parsers/sources/syml.ts | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/packages/yarnpkg-parsers/sources/syml.ts b/packages/yarnpkg-parsers/sources/syml.ts index 1cb24d0a52ef..02e5be1996e8 100644 --- a/packages/yarnpkg-parsers/sources/syml.ts +++ b/packages/yarnpkg-parsers/sources/syml.ts @@ -92,17 +92,15 @@ function stringifyValue(value: any, indentLevel: number, newLineIfObject: boolea : ``; - let keyPart: string; - let valuePart: string; - - // Yaml 1.2 spec says that keys over 1024 characters need to be prefixed with ? and the : goes in a new line - if (stringifiedKey.length > 1024) - keyPart = `? ${stringifiedKey}\n:`; - else keyPart = `${stringifiedKey}:`; - - if (stringifiedValue.startsWith(`\n`)) - valuePart = stringifiedValue; - else valuePart = ` ${stringifiedValue}`; + const keyPart = + // Yaml 1.2 spec says that keys over 1024 characters need to be prefixed with ? and the : goes in a new line + stringifiedKey.length > 1024 + ? `? ${stringifiedKey}\n:` + : `${stringifiedKey}:`; + + const valuePart = stringifiedValue.startsWith(`\n`) + ? stringifiedValue + : ` ${stringifiedValue}`; return `${recordIndentation}${keyPart}${valuePart}`; From 05c1e593dd8f9c35863289bbed122551880eee18 Mon Sep 17 00:00:00 2001 From: Elad Ossadon Date: Sun, 27 Mar 2022 10:14:37 -0700 Subject: [PATCH 4/5] formatting --- packages/yarnpkg-parsers/sources/syml.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/yarnpkg-parsers/sources/syml.ts b/packages/yarnpkg-parsers/sources/syml.ts index 02e5be1996e8..6024aadd5aea 100644 --- a/packages/yarnpkg-parsers/sources/syml.ts +++ b/packages/yarnpkg-parsers/sources/syml.ts @@ -92,12 +92,12 @@ function stringifyValue(value: any, indentLevel: number, newLineIfObject: boolea : ``; - const keyPart = + const keyPart = // Yaml 1.2 spec says that keys over 1024 characters need to be prefixed with ? and the : goes in a new line stringifiedKey.length > 1024 ? `? ${stringifiedKey}\n:` : `${stringifiedKey}:`; - + const valuePart = stringifiedValue.startsWith(`\n`) ? stringifiedValue : ` ${stringifiedValue}`; From ae919f4799e8a2fbd1201d7e5718041d1fefd655 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ma=C3=ABl=20Nison?= Date: Tue, 29 Mar 2022 14:03:10 +0200 Subject: [PATCH 5/5] Update syml.ts --- packages/yarnpkg-parsers/sources/syml.ts | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/packages/yarnpkg-parsers/sources/syml.ts b/packages/yarnpkg-parsers/sources/syml.ts index 6024aadd5aea..db5afceff162 100644 --- a/packages/yarnpkg-parsers/sources/syml.ts +++ b/packages/yarnpkg-parsers/sources/syml.ts @@ -91,18 +91,15 @@ function stringifyValue(value: any, indentLevel: number, newLineIfObject: boolea ? indent : ``; - - const keyPart = - // Yaml 1.2 spec says that keys over 1024 characters need to be prefixed with ? and the : goes in a new line - stringifiedKey.length > 1024 - ? `? ${stringifiedKey}\n:` - : `${stringifiedKey}:`; + // Yaml 1.2 spec says that keys over 1024 characters need to be prefixed with ? and the : goes in a new line + const keyPart = stringifiedKey.length > 1024 + ? `? ${stringifiedKey}\n:` + : `${stringifiedKey}:`; const valuePart = stringifiedValue.startsWith(`\n`) ? stringifiedValue : ` ${stringifiedValue}`; - return `${recordIndentation}${keyPart}${valuePart}`; }).join(indentLevel === 0 ? `\n` : ``) || `\n`;