Skip to content

Commit

Permalink
fix: handle closing tags inside attribute values (#9486)
Browse files Browse the repository at this point in the history
  • Loading branch information
dummdidumm authored Nov 16, 2023
1 parent 50abbc8 commit b2e1f1c
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 2 deletions.
5 changes: 5 additions & 0 deletions .changeset/twelve-ears-act.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'svelte': patch
---

fix: handle closing tags inside attribute values
6 changes: 4 additions & 2 deletions packages/svelte/src/compiler/preprocess/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -252,8 +252,10 @@ function stringify_tag_attributes(attributes) {
return value;
}

const regex_style_tags = /<!--[^]*?-->|<style(\s[^]*?)?(?:>([^]*?)<\/style>|\/>)/gi;
const regex_script_tags = /<!--[^]*?-->|<script(\s[^]*?)?(?:>([^]*?)<\/script>|\/>)/gi;
const regex_style_tags =
/<!--[^]*?-->|<style((?:\s+[^=>'"\/]+=(?:"[^"]*"|'[^']*'|[^>\s])|\s+[^=>'"\/]+)*\s*)(?:\/>|>([\S\s]*?)<\/style>)/g;
const regex_script_tags =
/<!--[^]*?-->|<script((?:\s+[^=>'"\/]+=(?:"[^"]*"|'[^']*'|[^>\s])|\s+[^=>'"\/]+)*\s*)(?:\/>|>([\S\s]*?)<\/script>)/g;

/**
* Calculate the updates required to process all instances of the specified tag.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
export default {
preprocess: {
script: ({ attributes }) =>
attributes.generics && attributes.generics.includes('>') ? { code: '' } : null
}
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<script generics="T extends Record<string, string>">
foo {}
</script>
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<script generics="T extends Record<string, string>"></script>

0 comments on commit b2e1f1c

Please sign in to comment.