Skip to content

Commit

Permalink
fix: should respect charset=utf-8 in data uri (#528)
Browse files Browse the repository at this point in the history
Close #291
  • Loading branch information
Jackie1210 authored Aug 11, 2023
1 parent 3f598c2 commit 0a05c92
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/handler/image.ts
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ export async function resolveImageData(

try {
decodedURI =
/data:(?<imageType>[a-z/+]+)(;(?<encodingType>base64|utf8))?,(?<dataString>.*)/g.exec(
/data:(?<imageType>[a-z/+]+)(;(charset=)?(?<encodingType>.*))?,(?<dataString>.*)/g.exec(
src
).groups as typeof decodedURI
} catch (err) {
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
18 changes: 18 additions & 0 deletions test/image.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -620,4 +620,22 @@ describe('background-image: url()', () => {

expect(toImage(svg, 100)).toMatchImageSnapshot()
})

it('should handle charset=utf-8', async () => {
const svg = await satori(
<div
style={{
width: '100px',
height: '100px',
display: 'flex',
backgroundImage:
'url(\'data:image/svg+xml;charset=utf-8,<svg xmlns="http://www.w3.org/2000/svg" width="40" height="40"><circle cx="20" cy="20" r="15" fill="#ee7621"/></svg>\')',
backgroundSize: '100px 100px',
}}
></div>,
{ width: 100, height: 100, fonts }
)

expect(toImage(svg, 100)).toMatchImageSnapshot()
})
})

1 comment on commit 0a05c92

@vercel
Copy link

@vercel vercel bot commented on 0a05c92 Aug 11, 2023

Choose a reason for hiding this comment

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

Please sign in to comment.