Skip to content

Commit

Permalink
perf: Prevent polynomial search time when folding plain & single-quot…
Browse files Browse the repository at this point in the history
…ed scalars
  • Loading branch information
eemeli committed Apr 17, 2021
1 parent 375b654 commit 32b84c1
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/compose/resolve-flow-scalar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,14 +86,16 @@ function singleQuotedValue(source: string, onError: ComposeErrorHandler) {
}

function foldLines(source: string) {
const first = /(.*?)[ \t]*\r?\n/sy
// The negative lookbehind here and in the `re` RegExp is to
// prevent causing a polynomial search time in certain cases.
const first = /(.*?)(?<![ \t])[ \t]*\r?\n/sy
let match = first.exec(source)
if (!match) return source

let pos = first.lastIndex
let res = match[1]
let sep = ' '
const re = /[ \t]*(.*?)[ \t]*\r?\n/sy
const re = /[ \t]*(.*?)(?:(?<![ \t])[ \t]*)?\r?\n/sy
re.lastIndex = pos
while ((match = re.exec(source))) {
const line = match[1]
Expand Down

0 comments on commit 32b84c1

Please sign in to comment.