Commit 5e200f1
committed
fix: text matching Object.prototype property names silently not rendered
Fixes #746.
`graphemeImages` was created as a plain object via `{ ...options.graphemeImages }`,
which means it inherits from `Object.prototype`. When the text being rendered
exactly matches an inherited property name (e.g. "constructor", "toString",
"valueOf", "hasOwnProperty"), the lookup `graphemeImages[text]` returned the
inherited method instead of `undefined`. Downstream code then treated that
function as an image URL and emitted `<image href="function Object() { [native
code] }" ...>` instead of rendering the text as glyph paths.
The fix changes the backing storage to a null-prototype object via
`Object.assign(Object.create(null), options.graphemeImages)`. Bracket lookups
for non-own properties now return `undefined` as expected, and the text falls
through to the normal glyph-rendering path. No behaviour change for legitimate
emoji/image keys.
Test plan: new case in `test/emoji.test.tsx` that renders the text
"constructor toString valueOf" without any graphemeImages and asserts the SVG
contains no `[native code]`, `[object Object]`, or `<image>` element. All
existing emoji and basic tests continue to pass.1 parent ab49faf commit 5e200f1
2 files changed
Lines changed: 22 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
73 | 73 | | |
74 | 74 | | |
75 | 75 | | |
76 | | - | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
77 | 84 | | |
78 | 85 | | |
79 | 86 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
116 | 116 | | |
117 | 117 | | |
118 | 118 | | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
119 | 133 | | |
0 commit comments