Skip to content

Commit e8e81fb

Browse files
committed
fix: handle mulitple escape sequences leading to quote
1 parent 014c302 commit e8e81fb

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

lib/migration_generator/operation.ex

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1351,7 +1351,7 @@ defmodule AshPostgres.MigrationGenerator.Operation do
13511351
},
13521352
table: table
13531353
}) do
1354-
check = String.replace(check, ~S["], ~S[\"])
1354+
check = String.replace(check, ~r/((?:\\)*)"/, ~S[\1\"])
13551355

13561356
if base_filter do
13571357
"create constraint(:#{as_atom(table)}, :#{as_atom(name)}, #{join(["check: \"(#{check}) OR NOT (#{base_filter})\")", option(:prefix, schema)])}"
@@ -1388,7 +1388,7 @@ defmodule AshPostgres.MigrationGenerator.Operation do
13881388
schema: schema,
13891389
table: table
13901390
}) do
1391-
check = String.replace(check, ~S["], ~S[\"])
1391+
check = String.replace(check, ~r/((?:\\)*)"/, ~S[\1\"])
13921392

13931393
if base_filter do
13941394
"create constraint(:#{as_atom(table)}, :#{as_atom(name)}, #{join(["check: \"#{base_filter} AND #{check}\")", option(:prefix, schema)])}"

test/migration_generator_test.exs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2240,11 +2240,16 @@ defmodule AshPostgres.MigrationGeneratorTest do
22402240
attributes do
22412241
uuid_primary_key(:id)
22422242
attribute(:price, :integer, public?: true)
2243+
attribute(:title, :string, public?: true)
22432244
end
22442245

22452246
postgres do
22462247
check_constraints do
22472248
check_constraint(:price, "price_must_be_positive", check: ~S["price" > 0])
2249+
2250+
check_constraint(:title, "title_must_conform_to_format",
2251+
check: "title ~= '(\"\\\"\\\\\")'"
2252+
)
22482253
end
22492254
end
22502255
end
@@ -2270,6 +2275,9 @@ defmodule AshPostgres.MigrationGeneratorTest do
22702275
assert file =~
22712276
~S[create constraint(:posts, :price_must_be_positive, check: "\"price\" > 0")]
22722277

2278+
assert file =~
2279+
"create constraint(:posts, :title_must_conform_to_format, check: \"title ~= '(\\\"\\\\\"\\\\\\\")'\""
2280+
22732281
defposts do
22742282
attributes do
22752283
uuid_primary_key(:id)

0 commit comments

Comments
 (0)