Skip to content

Commit fb9e8fa

Browse files
committed
fix(tsql): avoid polynomial backtracking in ORDER BY direction strip
1 parent d8c7c63 commit fb9e8fa

1 file changed

Lines changed: 3 additions & 1 deletion

File tree

internal-packages/tsql/src/query/printer.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -647,7 +647,9 @@ export class ClickHousePrinter {
647647
// ORDER BY must be led by the timeBucket column (alias or full expression).
648648
// Don't fight a user ordering like `ORDER BY count DESC`.
649649
const leadTerm = orderBy[0];
650-
const leadExpr = leadTerm.replace(/\s+(ASC|DESC)\s*$/i, "").trim();
650+
// Trim first so the direction match is anchored without a trailing `\s*$`, which
651+
// combined with the leading `\s+` would backtrack polynomially on all-whitespace input.
652+
const leadExpr = leadTerm.trim().replace(/\s+(?:ASC|DESC)$/i, "");
651653
const matchesBucket = (expr: string): boolean =>
652654
expr.toLowerCase() === bucketAlias!.toLowerCase() || expr === bucketSql;
653655
if (!matchesBucket(leadExpr)) {

0 commit comments

Comments
 (0)