Skip to content

Commit

Permalink
fix: avoid regex lookbehind for compatibility (#7270)
Browse files Browse the repository at this point in the history
Lookbehind isn't supported in Safari/JavaScriptCore environments.

Closes: #7026
  • Loading branch information
mohd-akram committed Jan 18, 2021
1 parent aea2786 commit 063d27f
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions src/query-builder/QueryBuilder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -624,12 +624,13 @@ export abstract class QueryBuilder<Entity> {

if (replacementKeys.length) {
statement = statement.replace(new RegExp(
`(?<=[ =\(]|^.{0})` +
// Avoid a lookbehind here since it's not well supported
`([ =\(]|^.{0})` +
`${escapeRegExp(replaceAliasNamePrefix)}(${replacementKeys.map(escapeRegExp).join("|")})` +
`(?=[ =\)\,]|.{0}$)`,
"gm"
), (_, p) =>
`${replacementAliasNamePrefix}${this.escape(replacements[p])}`
), (_, pre, p) =>
`${pre}${replacementAliasNamePrefix}${this.escape(replacements[p])}`
);
}
}
Expand Down

0 comments on commit 063d27f

Please sign in to comment.