Skip to content

Commit

Permalink
avoid adding double colon (#315)
Browse files Browse the repository at this point in the history
* avoid adding double colon

* Create beige-starfishes-worry.md
  • Loading branch information
JoviDeCroock committed Sep 11, 2023
1 parent bd818dc commit f1d81be
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 1 deletion.
5 changes: 5 additions & 0 deletions .changeset/beige-starfishes-worry.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"preact-render-to-string": patch
---

avoid adding double colon for namespaced attributes
2 changes: 1 addition & 1 deletion src/util.js
Original file line number Diff line number Diff line change
@@ -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/;

Expand Down
6 changes: 6 additions & 0 deletions test/render.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -337,6 +337,12 @@ describe('render', () => {
`<svg><image xlink:href="#"></image><foreignObject><div xlink:href="#"></div></foreignObject><g><image xlink:href="#"></image></g></svg>`
);
});

it('should not add extra colon on SVG elements', () => {
let rendered = render(<svg>{h('image', { 'xlink:href': '#' })}</svg>);

expect(rendered).to.equal(`<svg><image xlink:href="#"></image></svg>`);
});
});

describe('Functional Components', () => {
Expand Down

0 comments on commit f1d81be

Please sign in to comment.