mirror of
https://github.com/microsoft/TypeScript.git
synced 2025-11-18 17:21:48 +00:00
Simplify or optimize regexes with polynomial time worst cases (#44197)
* Simplify or optimize regexes with polynomial time worst cases * PR feedback & cleanup Co-authored-by: David Michon <dmichon-msft@users.noreply.github.com> * Use builtin scanner function for checking whitespace in fallback method (its faster) Co-authored-by: David Michon <dmichon-msft@users.noreply.github.com>
This commit is contained in:
co-authored by
David Michon
parent
2203228b62
commit
fcabb5c0cc
@@ -471,6 +471,9 @@ namespace ts {
|
||||
// An `Array` with extra properties is rendered as `[A, B, prop1: 1, prop2: 2]`. Most of
|
||||
// these aren't immediately useful so we trim off the `prop1: ..., prop2: ...` part from the
|
||||
// formatted string.
|
||||
// This regex can trigger slow backtracking because of overlapping potential captures.
|
||||
// We don't care, this is debug code that's only enabled with a debugger attached -
|
||||
// we're just taking note of it for anyone checking regex performance in the future.
|
||||
defaultValue = String(defaultValue).replace(/(?:,[\s\w\d_]+:[^,]+)+\]$/, "]");
|
||||
return `NodeArray ${defaultValue}`;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user