Skip to content

Commit 071be84

Browse files
nzakasmdjermanovic
andauthored
Merge commit from fork
* Fix runaway regex whitespace matching * Include negative lookbehind * Update packages/plugin-kit/tests/config-comment-parser.test.js Co-authored-by: Milos Djermanovic <milos.djermanovic@gmail.com> * Update packages/plugin-kit/tests/config-comment-parser.test.js Co-authored-by: Milos Djermanovic <milos.djermanovic@gmail.com> * Update packages/plugin-kit/tests/config-comment-parser.test.js Co-authored-by: Milos Djermanovic <milos.djermanovic@gmail.com> * Update packages/plugin-kit/tests/config-comment-parser.test.js Co-authored-by: Milos Djermanovic <milos.djermanovic@gmail.com> * Update packages/plugin-kit/src/config-comment-parser.js Co-authored-by: Milos Djermanovic <milos.djermanovic@gmail.com> --------- Co-authored-by: Milos Djermanovic <milos.djermanovic@gmail.com>
1 parent e73b1dc commit 071be84

File tree

2 files changed

+52
-1
lines changed

2 files changed

+52
-1
lines changed

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,9 @@ export class ConfigCommentParser {
9999
const items = /** @type {StringConfig} */ ({});
100100

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

104106
trimmedString.split(/\s|,+/u).forEach(name => {
105107
if (!name) {

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

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,55 @@ describe("ConfigCommentParser", () => {
7474
b: null,
7575
});
7676
});
77+
78+
it("should return an empty object for an empty string", () => {
79+
const code = "";
80+
const result = commentParser.parseStringConfig(code, comment);
81+
82+
assert.deepStrictEqual(result, {});
83+
});
84+
85+
it("should parse string config with one item, no value, and leading whitespace", () => {
86+
const code = `${" ".repeat(100000)}a`;
87+
const result = commentParser.parseStringConfig(code, comment);
88+
89+
assert.deepStrictEqual(result, {
90+
a: null,
91+
});
92+
});
93+
94+
it("should parse string config with one item, no value, and trailing whitespace", () => {
95+
const code = `a${" ".repeat(100000)}`;
96+
const result = commentParser.parseStringConfig(code, comment);
97+
98+
assert.deepStrictEqual(result, {
99+
a: null,
100+
});
101+
});
102+
103+
it("should parse string config with two items, no values, and whitespace in the middle", () => {
104+
const code = `a${" ".repeat(100000)}b`;
105+
const result = commentParser.parseStringConfig(code, comment);
106+
107+
assert.deepStrictEqual(result, {
108+
a: null,
109+
b: null,
110+
});
111+
});
112+
113+
it("should parse string config with multiple items with values separated by commas and lots of whitespace", () => {
114+
const whitespace = " ".repeat(100000);
115+
const code = `a: 1${whitespace},${whitespace}b: 2${whitespace},${whitespace}c: 3${whitespace},${whitespace}d: 4`;
116+
const result = commentParser.parseStringConfig(code, comment);
117+
118+
assert.deepStrictEqual(result, {
119+
a: "1",
120+
b: "2",
121+
c: "3",
122+
d: "4",
123+
});
124+
});
125+
77126
});
78127

79128
describe("parseListConfig", () => {

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy