Skip to content

Commit 555398d

Browse files
committed
close #38, update data uri regexp
1 parent da182f4 commit 555398d

File tree

2 files changed

+28
-16
lines changed

2 files changed

+28
-16
lines changed

src/snapshot.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ function extractOrigin(url: string): string {
6363

6464
const URL_IN_CSS_REF = /url\((?:(')([^']*)'|(")([^"]*)"|([^)]*))\)/gm;
6565
const RELATIVE_PATH = /^(?!www\.|(?:http|ftp)s?:\/\/|[A-Za-z]:\\|\/\/).*/;
66-
const DATA_URI = /^(data:)([\w\/\+\-]+);(charset=[\w-]+|base64|utf-?8).*,(.*)/i;
66+
const DATA_URI = /^(data:)([^,]*),(.*)/i;
6767
export function absoluteToStylesheet(
6868
cssText: string | null,
6969
href: string,

test/snapshot.test.ts

Lines changed: 27 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -74,11 +74,21 @@ describe('absolute url to stylesheet', () => {
7474

7575
it('preserves quotes around inline svgs with spaces', () => {
7676
expect(
77-
absoluteToStylesheet("url(\"data:image/svg+xml;charset=utf-8,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 8 8'%3E%3Cpath fill='%2328a745' d='M3'/%3E%3C/svg%3E\")", href),
78-
).to.equal("url(\"data:image/svg+xml;charset=utf-8,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 8 8'%3E%3Cpath fill='%2328a745' d='M3'/%3E%3C/svg%3E\")");
77+
absoluteToStylesheet(
78+
"url(\"data:image/svg+xml;charset=utf-8,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 8 8'%3E%3Cpath fill='%2328a745' d='M3'/%3E%3C/svg%3E\")",
79+
href,
80+
),
81+
).to.equal(
82+
"url(\"data:image/svg+xml;charset=utf-8,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 8 8'%3E%3Cpath fill='%2328a745' d='M3'/%3E%3C/svg%3E\")",
83+
);
7984
expect(
80-
absoluteToStylesheet('url(\'data:image/svg+xml;utf8,<svg width="28" height="32" viewBox="0 0 28 32" xmlns="http://www.w3.org/2000/svg"><path d="M27 14C28" fill="white"/></svg>\')', href),
81-
).to.equal('url(\'data:image/svg+xml;utf8,<svg width="28" height="32" viewBox="0 0 28 32" xmlns="http://www.w3.org/2000/svg"><path d="M27 14C28" fill="white"/></svg>\')');
85+
absoluteToStylesheet(
86+
'url(\'data:image/svg+xml;utf8,<svg width="28" height="32" viewBox="0 0 28 32" xmlns="http://www.w3.org/2000/svg"><path d="M27 14C28" fill="white"/></svg>\')',
87+
href,
88+
),
89+
).to.equal(
90+
'url(\'data:image/svg+xml;utf8,<svg width="28" height="32" viewBox="0 0 28 32" xmlns="http://www.w3.org/2000/svg"><path d="M27 14C28" fill="white"/></svg>\')',
91+
);
8292
});
8393
it('can handle empty path', () => {
8494
expect(absoluteToStylesheet(`url('')`, href)).to.equal(`url('')`);
@@ -87,24 +97,26 @@ describe('absolute url to stylesheet', () => {
8797

8898
describe('isBlockedElement()', () => {
8999
const subject = (html: string, opt: any = {}) =>
90-
_isBlockedElement(render(html), 'rr-block', opt.blockSelector)
100+
_isBlockedElement(render(html), 'rr-block', opt.blockSelector);
91101

92102
const render = (html: string): HTMLElement =>
93-
JSDOM.fragment(html).querySelector('div')!
103+
JSDOM.fragment(html).querySelector('div')!;
94104

95105
it('can handle empty elements', () => {
96-
expect(subject('<div />')).to.equal(false)
97-
})
106+
expect(subject('<div />')).to.equal(false);
107+
});
98108

99109
it('blocks prohibited className', () => {
100-
expect(subject('<div class="foo rr-block bar" />')).to.equal(true)
101-
})
110+
expect(subject('<div class="foo rr-block bar" />')).to.equal(true);
111+
});
102112

103113
it('does not block random data selector', () => {
104-
expect(subject('<div data-rr-block />')).to.equal(false)
105-
})
114+
expect(subject('<div data-rr-block />')).to.equal(false);
115+
});
106116

107117
it('blocks blocked selector', () => {
108-
expect(subject('<div data-rr-block />', { blockSelector: '[data-rr-block]' })).to.equal(true)
109-
})
110-
})
118+
expect(
119+
subject('<div data-rr-block />', { blockSelector: '[data-rr-block]' }),
120+
).to.equal(true);
121+
});
122+
});

0 commit comments

Comments
 (0)