Skip to content
This repository has been archived by the owner on Oct 9, 2020. It is now read-only.

Fix: idPrefix regex to support style attribute #90

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/transformer.js
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ function createClassPrefix(classPrefix) {
}

function createIdPrefix(idPrefix) {
var url_pattern = /^url\(#.+\)$/i;
var url_pattern = /url\(#.+?\)/gi;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it wont work for this

<path mask="url(#foo")>

I guess keeping both can be better

Copy link
Author

@koox00 koox00 Feb 10, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@anikethsaha It passes the tests though.
why wouldn't it work?

return function prefixIds(tag) {
var idIdx = getAttributeIndex(tag, 'id');
if (idIdx !== -1) {
Expand Down
2 changes: 1 addition & 1 deletion tests/fixtures/with-ids.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
5 changes: 2 additions & 3 deletions tests/svg-inline-loader.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,12 +56,11 @@ describe('getExtractedSVG()', function(){
var svgWithStyle = require('raw!./fixtures/with-ids.svg');
var processedStyleInsertedSVG = SVGInlineLoader.getExtractedSVG(svgWithStyle, { idPrefix: 'test.prefix-' });


assert.isTrue( processedStyleInsertedSVG.match(/test\.prefix-foo/g).length === 3 );
assert.isTrue( processedStyleInsertedSVG.match(/test\.prefix-foo/g).length === 4 );
// // replaces xlink:href=
assert.isTrue( processedStyleInsertedSVG.match(/xlink:href=/g).length === 1 );
// // replaces url(#foo)
assert.isTrue( processedStyleInsertedSVG.match(/url\(#test\.prefix-foo\)/g).length === 1 );
assert.isTrue( processedStyleInsertedSVG.match(/url\(#test\.prefix-foo\)/g).length === 2 );
});

it('should be able to specify tags to be removed by `removingTags` option', function () {
Expand Down