From f1d81be1e56d64bf7bf0ecc975a7b54d2db2ad45 Mon Sep 17 00:00:00 2001 From: Jovi De Croock Date: Mon, 11 Sep 2023 07:59:46 +0200 Subject: [PATCH] avoid adding double colon (#315) * avoid adding double colon * Create beige-starfishes-worry.md --- .changeset/beige-starfishes-worry.md | 5 +++++ src/util.js | 2 +- test/render.test.js | 6 ++++++ 3 files changed, 12 insertions(+), 1 deletion(-) create mode 100644 .changeset/beige-starfishes-worry.md diff --git a/.changeset/beige-starfishes-worry.md b/.changeset/beige-starfishes-worry.md new file mode 100644 index 00000000..4feae9e2 --- /dev/null +++ b/.changeset/beige-starfishes-worry.md @@ -0,0 +1,5 @@ +--- +"preact-render-to-string": patch +--- + +avoid adding double colon for namespaced attributes diff --git a/src/util.js b/src/util.js index bc80ea48..397d01ad 100644 --- a/src/util.js +++ b/src/util.js @@ -1,6 +1,6 @@ export const VOID_ELEMENTS = /^(?:area|base|br|col|embed|hr|img|input|link|meta|param|source|track|wbr)$/; export const UNSAFE_NAME = /[\s\n\\/='"\0<>]/; -export const NAMESPACE_REPLACE_REGEX = /^(xlink|xmlns|xml)(:|[A-Z])/; +export const NAMESPACE_REPLACE_REGEX = /^(xlink|xmlns|xml)([A-Z])/; export const HTML_LOWER_CASE = /^accessK|^auto[A-Z]|^ch|^col|cont|cross|dateT|encT|form[A-Z]|frame|hrefL|inputM|maxL|minL|noV|playsI|readO|rowS|spellC|src[A-Z]|tabI|item[A-Z]/; export const SVG_CAMEL_CASE = /^ac|^ali|arabic|basel|cap|clipPath$|clipRule$|color|dominant|enable|fill|flood|font|glyph[^R]|horiz|image|letter|lighting|marker[^WUH]|overline|panose|pointe|paint|rendering|shape|stop|strikethrough|stroke|text[^L]|transform|underline|unicode|units|^v[^i]|^w|^xH/; diff --git a/test/render.test.js b/test/render.test.js index e6b6fe1c..f8060d80 100644 --- a/test/render.test.js +++ b/test/render.test.js @@ -337,6 +337,12 @@ describe('render', () => { `
` ); }); + + it('should not add extra colon on SVG elements', () => { + let rendered = render({h('image', { 'xlink:href': '#' })}); + + expect(rendered).to.equal(``); + }); }); describe('Functional Components', () => {