Skip to content

Commit

Permalink
🔨 fix problematic regex
Browse files Browse the repository at this point in the history
  • Loading branch information
danyx23 committed Dec 15, 2023
1 parent 8e3146d commit c9ba44b
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions packages/@ourworldindata/utils/src/wordpressUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,13 @@ import { FormattingOptions, KeyValueProps } from "./owidTypes.js"

export const extractFormattingOptions = (html: string): FormattingOptions => {
const formattingOptionsMatch = html.match(
/<!--\s*formatting-options\s+(.*)\s*-->/
/<!--\s*formatting-options(.*)-->/
)

Check failure

Code scanning / CodeQL

Polynomial regular expression used on uncontrolled data High

This
regular expression
that depends on
library input
may run slow on strings starting with '<!--formatting-options' and with many repetitions of '<!--formatting-optionsa'.
const innerFormattingOptions = formattingOptionsMatch
? formattingOptionsMatch[1].trim()
: ""
return formattingOptionsMatch
? parseFormattingOptions(formattingOptionsMatch[1])
? parseFormattingOptions(innerFormattingOptions)
: {}
}

Expand Down

0 comments on commit c9ba44b

Please sign in to comment.