Commit 9feec94
authored
fix: text matching Object.prototype property names rendered as image (#768)
## Problem (#746)
When text content passed to Satori **exactly matched** an
`Object.prototype` property name (e.g. `"constructor"`, `"toString"`,
`"valueOf"`), the text was silently not rendered. Instead, an `<image>`
element with an invalid `href` was emitted.
### Root Cause
Two locations in `src/text/index.ts` used bracket-notation lookup on a
user-provided `graphemeImages` object:
1. `isImage(s)` (line 122): `graphemeImages[s]` — when `s` is
`"constructor"`, this returns `Object.prototype.constructor` (a truthy
function), so the text was incorrectly treated as an image.
2. Rendering path (line 558): `graphemeImages[text]` — same issue,
returns the inherited property instead of `undefined`.
### Fix
Use `Object.prototype.hasOwnProperty.call()` to check for own properties
before accessing the value:
```ts
// Before
graphemeImages[s]
// After
Object.prototype.hasOwnProperty.call(graphemeImages, s) && graphemeImages[s]
```
### Testing
All 433 existing tests pass. The fix only affects edge cases where text
exactly matches `Object.prototype` property names — normal usage is
unaffected.1 parent 91ade3b commit 9feec94
1 file changed
Lines changed: 10 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
119 | 119 | | |
120 | 120 | | |
121 | 121 | | |
122 | | - | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
123 | 127 | | |
124 | 128 | | |
125 | 129 | | |
| |||
551 | 555 | | |
552 | 556 | | |
553 | 557 | | |
554 | | - | |
| 558 | + | |
| 559 | + | |
| 560 | + | |
| 561 | + | |
| 562 | + | |
555 | 563 | | |
556 | 564 | | |
557 | 565 | | |
| |||
0 commit comments