From 80eb114420bc2f52a1a016a8f5c8471555798d66 Mon Sep 17 00:00:00 2001 From: Gil Barbara Date: Sat, 5 Aug 2023 22:34:29 -0300 Subject: [PATCH] Update dataURI regex pattern Closes #203 --- src/index.tsx | 2 +- test/__snapshots__/index.spec.tsx.snap | 29 ++++++++++++++++++++++++++ test/index.spec.tsx | 15 +++++++++++++ 3 files changed, 45 insertions(+), 1 deletion(-) diff --git a/src/index.tsx b/src/index.tsx index a7c605d..880dec9 100644 --- a/src/index.tsx +++ b/src/index.tsx @@ -206,7 +206,7 @@ export default class InlineSVG extends React.PureComponent { return; } - const dataURI = src.match(/data:image\/svg[^,]*?(;base64)?,(.*)/); + const dataURI = src.match(/^data:image\/svg[^,]*?(;base64)?,(.*)/u); let inlineSrc; if (dataURI) { diff --git a/test/__snapshots__/index.spec.tsx.snap b/test/__snapshots__/index.spec.tsx.snap index 3d58ab5..8879abf 100644 --- a/test/__snapshots__/index.spec.tsx.snap +++ b/test/__snapshots__/index.spec.tsx.snap @@ -2290,6 +2290,35 @@ exports[`react-inlinesvg basic functionality should render an urlEncoded src 1`] `; +exports[`react-inlinesvg basic functionality should render an urlEncodedWithBase64 src 1`] = ` + + + URL Encoded With Base 64 + + + + + + + + +`; + exports[`react-inlinesvg basic functionality should transform the SVG text with the preProcessor prop 1`] = ` ', @@ -79,6 +81,19 @@ describe('react-inlinesvg', () => { expect(container.querySelector('svg')).toMatchSnapshot(); }); + it('should render an urlEncodedWithBase64 src', async () => { + const { container } = setup({ + src: fixtures.urlEncodedWithBase64, + title: 'URL Encoded With Base 64', + }); + + await waitFor(() => { + expect(mockOnLoad).toHaveBeenCalledTimes(1); + }); + + expect(container.querySelector('svg')).toMatchSnapshot(); + }); + it('should render a svg string src', async () => { const { container } = setup({ src: fixtures.string,