diff --git a/src/filter.ts b/src/filter.ts index 45916892..63bb54a9 100644 --- a/src/filter.ts +++ b/src/filter.ts @@ -19,7 +19,7 @@ const formatValue = ( } if (typeof value === "string") { - return `"${value}"`; + return `"${value.replace(/"/g, '\\"')}"`; } if (value instanceof Date) { diff --git a/test/filter-any.test.ts b/test/filter-any.test.ts index 5060b7f5..94fd862a 100644 --- a/test/filter-any.test.ts +++ b/test/filter-any.test.ts @@ -12,6 +12,11 @@ testFilter( prismic.filter.any("my.product.out_of_stock", [true, false]), ); +testFilter( + '[any(my.product.description, ["\\"quote\\""])]', + prismic.filter.any("my.product.description", ['"quote"']), +); + testFilter( "[any(my.product.restock_date, [1600000000000, 1700000000000])]", prismic.filter.any("my.product.restock_date", [ diff --git a/test/filter-at.test.ts b/test/filter-at.test.ts index 10928b10..ee2b990e 100644 --- a/test/filter-at.test.ts +++ b/test/filter-at.test.ts @@ -12,6 +12,11 @@ testFilter( prismic.filter.at("document.tags", ["Macaron", "Cupcake"]), ); +testFilter( + '[at(my.product.description, "\\"quote\\"")]', + prismic.filter.at("my.product.description", '"quote"'), +); + testFilter( "[at(my.product.price, 50)]", prismic.filter.at("my.product.price", 50), diff --git a/test/filter-fulltext.test.ts b/test/filter-fulltext.test.ts index 84f19dd2..bab6f5eb 100644 --- a/test/filter-fulltext.test.ts +++ b/test/filter-fulltext.test.ts @@ -16,3 +16,8 @@ testFilter( '[fulltext(my.product.title, "phone")]', prismic.filter.fulltext("my.product.title", "phone"), ); + +testFilter( + '[fulltext(my.product.description, "\\"quote\\"")]', + prismic.filter.fulltext("my.product.description", '"quote"'), +); diff --git a/test/filter-in.test.ts b/test/filter-in.test.ts index dcf2b5c1..5b0081ce 100644 --- a/test/filter-in.test.ts +++ b/test/filter-in.test.ts @@ -11,3 +11,8 @@ testFilter( '[in(my.page.uid, ["myuid1", "myuid2"])]', prismic.filter.in("my.page.uid", ["myuid1", "myuid2"]), ); + +testFilter( + '[in(my.product.description, ["\\"quote\\""])]', + prismic.filter.in("my.product.description", ['"quote"']), +); diff --git a/test/filter-not.test.ts b/test/filter-not.test.ts index 59ff7577..e2d8cedb 100644 --- a/test/filter-not.test.ts +++ b/test/filter-not.test.ts @@ -12,6 +12,11 @@ testFilter( prismic.filter.not("document.tags", ["Macaron", "Cupcake"]), ); +testFilter( + '[not(my.product.description, "\\"quote\\"")]', + prismic.filter.not("my.product.description", '"quote"'), +); + testFilter( "[not(my.product.price, 50)]", prismic.filter.not("my.product.price", 50),