Skip to content

Commit b283f64

Browse files
fix: potential quadratic runtime in regular expression (#240)
1 parent bd4bf23 commit b283f64

File tree

2 files changed

+6
-1
lines changed

2 files changed

+6
-1
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ export class ConfigCommentParser {
155155
* But we are supporting that. So this is a fallback for that.
156156
*/
157157
const normalizedString = string
158-
.replace(/([-a-zA-Z0-9/]+):/gu, '"$1":')
158+
.replace(/(?<![-a-zA-Z0-9/])([-a-zA-Z0-9/]+):/gu, '"$1":')
159159
.replace(/(\]|[0-9])\s+(?=")/u, "$1,");
160160

161161
try {

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -254,6 +254,11 @@ describe("ConfigCommentParser", () => {
254254
},
255255
});
256256
});
257+
258+
it("should not timeout for large inputs", () => {
259+
const code = `${"A".repeat(100_000)}?: 1 B: 2`;
260+
commentParser.parseJSONLikeConfig(code);
261+
});
257262
});
258263

259264
describe("parseDirective", () => {

0 commit comments

Comments
 (0)