From fad3f3d3136f5f06241cd43a92fdfbaf3c57ba79 Mon Sep 17 00:00:00 2001 From: Fermain Date: Tue, 17 Dec 2024 11:17:45 +0200 Subject: [PATCH 1/2] Using single quotes in a label causes a parsing error #4 --- src/utils/transform.utils.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/utils/transform.utils.ts b/src/utils/transform.utils.ts index 2b74fe7..a0104df 100644 --- a/src/utils/transform.utils.ts +++ b/src/utils/transform.utils.ts @@ -61,10 +61,11 @@ export function applyDescription(field: Decap.CmsField, result: TransformResult) // derive potential description const description = field.hint ?? field.label ?? field.name; if (description === undefined) return result; + const safeDescription = description.replace(/'/g, "\\'"); // set a description return { - compiled: `${result.compiled}.describe('${description}')`, + compiled: `${result.compiled}.describe('${safeDescription}')`, dependencies: ['z', ...result.dependencies], }; } From 09d8da993fc51f0581e7bb96cbd1e27b8b25f2af Mon Sep 17 00:00:00 2001 From: Fermain Date: Tue, 17 Dec 2024 11:18:01 +0200 Subject: [PATCH 2/2] Adds a test case for quote types #4 --- public/examples/quotes.yml | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 public/examples/quotes.yml diff --git a/public/examples/quotes.yml b/public/examples/quotes.yml new file mode 100644 index 0000000..05af855 --- /dev/null +++ b/public/examples/quotes.yml @@ -0,0 +1,17 @@ +collections: + - name: "example" + label: "Example Case" + folder: "src/content/examples" + fields: + - name: "control_field" + label: "control string" + widget: "hidden" + - name: "single_quote_field" + label: "string containing ' quote" + widget: "hidden" + - name: "double_quote_field" + label: 'string containing " quote' + widget: "hidden" + - name: "tick_quote_field" + label: "string containing ` quote" + widget: "hidden" \ No newline at end of file