Skip to content

Commit b0df643

Browse files
fix: preserve closing quotes in regex patterns for CREATE DOMAIN CHECK constraints
- Fix deparser bug where JavaScript String.replace() was interpreting $ characters in regex patterns as special replacement syntax - Changed BoolExpr AND_EXPR and OR_EXPR cases to use function callbacks in replace() calls - Ensures complete string preservation through deparser pipeline for regex patterns ending with $ - All misc-launchql-ext-types tests now pass with valid SQL generation that can be reparsed successfully Fixes issue where: Input: CREATE DOMAIN attachment AS jsonb CHECK (value ?& ARRAY['url', 'mime'] AND (value ->> 'url') ~ '^(https?)://[^\s/$.?#].[^\s]*$') Output: CREATE DOMAIN attachment AS jsonb CHECK (value ?& ARRAY['url', 'mime'] AND (value ->> 'url') ~ '^(https?)://[^\s/$.?#].[^\s]*$') Technical fix: formatStr.replace('%s', joinedArgs) -> formatStr.replace('%s', () => joinedArgs) Co-Authored-By: Dan Lynch <[email protected]>
1 parent 067d75e commit b0df643

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

packages/deparser/src/deparser.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -386,6 +386,8 @@ export class Deparser implements DeparserVisitor {
386386
let leftExpr = this.visit(lexpr, context);
387387
let rightExpr = this.visit(rexpr, context);
388388

389+
390+
389391
// Check if left expression needs parentheses
390392
let leftNeedsParens = false;
391393
if (lexpr && 'A_Expr' in lexpr && lexpr.A_Expr?.kind === 'AEXPR_OP') {
@@ -973,16 +975,15 @@ export class Deparser implements DeparserVisitor {
973975
if (context.bool) {
974976
formatStr = '(%s)';
975977
}
976-
977978
const boolContext = { ...context, bool: true };
978979

979980
switch (boolop) {
980981
case 'AND_EXPR':
981982
const andArgs = args.map(arg => this.visit(arg, boolContext)).join(' AND ');
982-
return formatStr.replace('%s', andArgs);
983+
return formatStr.replace('%s', () => andArgs);
983984
case 'OR_EXPR':
984985
const orArgs = args.map(arg => this.visit(arg, boolContext)).join(' OR ');
985-
return formatStr.replace('%s', orArgs);
986+
return formatStr.replace('%s', () => orArgs);
986987
case 'NOT_EXPR':
987988
return `NOT (${this.visit(args[0], context)})`;
988989
default:

0 commit comments

Comments
 (0)