From 911b655cddbceb2e621bdc339fbed5304793da63 Mon Sep 17 00:00:00 2001 From: Simon H <5968653+dummdidumm@users.noreply.github.com> Date: Wed, 3 Feb 2021 15:18:56 +0100 Subject: [PATCH] (fix) case sensitive script/style snipping (#200) Fixes #198 --- CHANGELOG.md | 1 + src/lib/snipTagContent.ts | 2 +- .../samples/component-style-script-tagname.html | 10 ++++++++++ 3 files changed, 12 insertions(+), 1 deletion(-) create mode 100644 test/printer/samples/component-style-script-tagname.html diff --git a/CHANGELOG.md b/CHANGELOG.md index 2f8b01ff..2c8a7700 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,7 @@ ## 2.1.2 (Unreleased) * Keep whitespace around script/style tags ([#197](https://github.com/sveltejs/prettier-plugin-svelte/issues/197)) +* Make script/style tag snipping case sensitive ([#198](https://github.com/sveltejs/prettier-plugin-svelte/issues/198)) ## 2.1.1 diff --git a/src/lib/snipTagContent.ts b/src/lib/snipTagContent.ts index 1f699551..0f8d1190 100644 --- a/src/lib/snipTagContent.ts +++ b/src/lib/snipTagContent.ts @@ -1,7 +1,7 @@ export const snippedTagContentAttribute = '✂prettier:content✂'; export function snipTagContent(tagName: string, source: string, placeholder = ''): string { - const regex = new RegExp(`<${tagName}([^]*?)>([^]*?)<\/${tagName}>`, 'gi'); + const regex = new RegExp(`<${tagName}([^]*?)>([^]*?)<\/${tagName}>`, 'g'); return source.replace(regex, (_, attributes, content) => { const encodedContent = Buffer.from(content).toString('base64'); return `<${tagName}${attributes} ${snippedTagContentAttribute}="${encodedContent}">${placeholder}</${tagName}>`; diff --git a/test/printer/samples/component-style-script-tagname.html b/test/printer/samples/component-style-script-tagname.html new file mode 100644 index 00000000..e3e40d73 --- /dev/null +++ b/test/printer/samples/component-style-script-tagname.html @@ -0,0 +1,10 @@ +<script></script> + +<Script /> +<Script>hello</Script> +<ScriptedContent /> +<StyledText /> +<Style /> +<Style>hello</Style> + +<style></style>