Skip to content
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
9 changes: 8 additions & 1 deletion src/satori.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,14 @@ export default async function satori(
root.setJustifyContent(Yoga.JUSTIFY_FLEX_START)
root.setOverflow(Yoga.OVERFLOW_HIDDEN)

const graphemeImages = { ...options.graphemeImages }
// Null-prototype object so that `graphemeImages[text]` lookups for strings
// that match `Object.prototype` property names (e.g. "constructor",
// "toString", "valueOf") return `undefined` instead of inherited methods.
// See https://github.com/vercel/satori/issues/746.
const graphemeImages: Record<string, string> = Object.assign(
Object.create(null),
options.graphemeImages
)
// Some Chinese characters have different glyphs in Chinese and
// Japanese, but their Unicode is the same. If the user needs to display
// the Chinese and Japanese characters simultaneously correctly, the user
Expand Down
14 changes: 14 additions & 0 deletions test/emoji.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -116,4 +116,18 @@ describe('Emojis', () => {

expect(await toImage(svg)).toMatchImageSnapshot()
})

// https://github.com/vercel/satori/issues/746
it('should render text that matches Object.prototype property names', async () => {
const svg = await satori(<div>constructor toString valueOf</div>, {
width: 200,
height: 100,
fonts,
})
// The text used to be silently replaced with the inherited prototype
// method, e.g. `<image href="function Object() { [native code] }" .../>`.
expect(svg).not.toContain('[native code]')
expect(svg).not.toContain('[object Object]')
expect(svg).not.toContain('<image ')
})
})