Skip to content

Commit 2db5221

Browse files
author
Sam Shelley
committed
Fix element classNames/ids for objects when using classIdPrefix property
The classIdPrefix would previously add the '.className' version of the class to both the style class and the rendered react component. Instead only include the prefix (. or #) for the style, not the actual elements.
1 parent bcf3780 commit 2db5221

File tree

2 files changed

+5
-4
lines changed

2 files changed

+5
-4
lines changed

lib/sanitize/filters/prefix-style-class-id.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,10 @@ function processStyles (opts, source) {
2626
replace(
2727
CLASSNAME_OR_ID_SELECTOR_REGEX,
2828
function (match, pre, post) {
29-
var newname = pre + opts.prefix + post;
30-
opts.cache[post] = newname;
31-
return newname;
29+
// Set the cached version to not include the prefix (the dot) so that the className or id
30+
// is 'className' instead of '.className'
31+
opts.cache[post] = opts.prefix + post;
32+
return pre + opts.prefix + post;
3233
}
3334
);
3435
});

test/unit/xml/parse.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ describe('svg-react-loader/lib/xml/parse', () => {
177177
{
178178
tagname: 'path',
179179
props: {
180-
className: ".styles-test__st0",
180+
className: "styles-test__st0",
181181
d: "M14.5,18v2h21v-2H14.5z M14.5,26h21v-2h-21V26z M14.5,32h21v-2h-21V32z"
182182
}
183183
}

0 commit comments

Comments
 (0)