Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Santises single quotes in describe template #5

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions public/examples/quotes.yml
Original file line number Diff line number Diff line change
@@ -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"
3 changes: 2 additions & 1 deletion src/utils/transform.utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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],
};
}
Expand Down