Skip to content

Commit

Permalink
Merge commit from fork
Browse files Browse the repository at this point in the history
* Fix runaway regex whitespace matching

* Include negative lookbehind

* Update packages/plugin-kit/tests/config-comment-parser.test.js

Co-authored-by: Milos Djermanovic <[email protected]>

* Update packages/plugin-kit/tests/config-comment-parser.test.js

Co-authored-by: Milos Djermanovic <[email protected]>

* Update packages/plugin-kit/tests/config-comment-parser.test.js

Co-authored-by: Milos Djermanovic <[email protected]>

* Update packages/plugin-kit/tests/config-comment-parser.test.js

Co-authored-by: Milos Djermanovic <[email protected]>

* Update packages/plugin-kit/src/config-comment-parser.js

Co-authored-by: Milos Djermanovic <[email protected]>

---------

Co-authored-by: Milos Djermanovic <[email protected]>
  • Loading branch information
nzakas and mdjermanovic authored Nov 13, 2024
1 parent e73b1dc commit 071be84
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 1 deletion.
4 changes: 3 additions & 1 deletion packages/plugin-kit/src/config-comment-parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,9 @@ export class ConfigCommentParser {
const items = /** @type {StringConfig} */ ({});

// Collapse whitespace around `:` and `,` to make parsing easier
const trimmedString = string.replace(/\s*([:,])\s*/gu, "$1");
const trimmedString = string
.trim()
.replace(/(?<!\s)\s*([:,])\s*/gu, "$1");

trimmedString.split(/\s|,+/u).forEach(name => {
if (!name) {
Expand Down
49 changes: 49 additions & 0 deletions packages/plugin-kit/tests/config-comment-parser.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,55 @@ describe("ConfigCommentParser", () => {
b: null,
});
});

it("should return an empty object for an empty string", () => {
const code = "";
const result = commentParser.parseStringConfig(code, comment);

assert.deepStrictEqual(result, {});
});

it("should parse string config with one item, no value, and leading whitespace", () => {
const code = `${" ".repeat(100000)}a`;
const result = commentParser.parseStringConfig(code, comment);

assert.deepStrictEqual(result, {
a: null,
});
});

it("should parse string config with one item, no value, and trailing whitespace", () => {
const code = `a${" ".repeat(100000)}`;
const result = commentParser.parseStringConfig(code, comment);

assert.deepStrictEqual(result, {
a: null,
});
});

it("should parse string config with two items, no values, and whitespace in the middle", () => {
const code = `a${" ".repeat(100000)}b`;
const result = commentParser.parseStringConfig(code, comment);

assert.deepStrictEqual(result, {
a: null,
b: null,
});
});

it("should parse string config with multiple items with values separated by commas and lots of whitespace", () => {
const whitespace = " ".repeat(100000);
const code = `a: 1${whitespace},${whitespace}b: 2${whitespace},${whitespace}c: 3${whitespace},${whitespace}d: 4`;
const result = commentParser.parseStringConfig(code, comment);

assert.deepStrictEqual(result, {
a: "1",
b: "2",
c: "3",
d: "4",
});
});

});

describe("parseListConfig", () => {
Expand Down

0 comments on commit 071be84

Please sign in to comment.