EmbeddedFont#embed crashes when postscriptName is a Uint8Array (Hermes / React Native)
维护者通常 1 天内回复
还没有人认领这个 Issue。
- #1753 来自 @pratik-desgn —— 已关闭,未合并
评估
- 难度
- 2/5
- 预计耗时
- 1-3 小时
- 新手友好度
- 58/100
- Issue 类型
- 缺陷
- 描述清晰度
- 描述清楚
- 活跃度
- 停滞
- 技术栈
- javascript, react-native
- 领域
- mobile-dev
调研方向
检查 src/pdfkit 中报告的 built bundle 行附近的 EmbeddedFont#embed,并跟踪 postscriptName 在 PDF 生成过程中是如何使用的。在 Hermes 下使用名称为 Uint8Array 的字体复现该故障,然后验证字体嵌入完成且不会出现 replaceAll TypeError。
由索引模型根据 Issue 内容生成。
描述
In EmbeddedFont#embed (src/pdfkit, line ~32447 in the built bundle), the code assumes this.font.postscriptName is always a string:
const name = tag + '+' + this.font.postscriptName?.replaceAll(' ', '_');
However, fontkit's readString() returns a raw Uint8Array when TextDecoder doesn't support the requested encoding (e.g. x-mac-roman, utf-16be). This happens on Hermes (React Native), which only supports utf-8 and utf-16le.
This causes a TypeError: replaceAll is not a function at PDF generation time.
Suggested fix
const _psName = this.font.postscriptName;
const _psStr = typeof _psName === 'string'
? _psName
: _psName instanceof Uint8Array
? Array.from(_psName, b => String.fromCharCode(b)).join('')
: String(_psName || '');
const name = tag + '+' + _psStr.replace(/ /g, '_');
This handles all three cases (string, Uint8Array, null/undefined) and also replaces .replaceAll() with .replace(/ /g, '_') for broader engine compatibility.
Your environment
- pdfkit: 0.17.2
- pdfmake: 0.3.3
- React Native: 0.81.4
- Expo: 54.0.10
- React: 19.1.0
- JS Engine: Hermes
- Node: 20.19.5
- Platform: iOS / Android
- 主要语言
- JavaScript
- 星标
- 10.7k
- 派生
- 1.2k
- 平均合并
- 21 小时 41 分钟
- 30 天内合并 PR
- 27
环境准备
- 没有 Dockerfile 或 Docker Compose 文件
- 有 Pull Request 模板
- 阅读贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
foliojs/pdfkit 的其他 Issue
-
难度 2/5 1-3 小时 新手友好度 72/100
维护者通常 1 天内回复
-
PDFKit crashes when providing fonts as Buffer in table可能已有人在做 @ykw9263 于 132 天前认领。 未关闭
难度 2/5 1-3 小时 新手友好度 72/100
foliojs/pdfkit#1743 · 13 条评论 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 72/100
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 62/100
foliojs/pdfkit#1512 · 1 条评论 · 2 个 reaction ·
维护者通常 1 天内回复
-
难度 3/5 1-2 天 新手友好度 45/100
维护者通常 1 天内回复
相似的 Issue
-
502 on Node 26: ERR_INVALID_ARG_VALUE: Setting the TLS ServerName to an IP address is not permitted未关闭
难度 2/5 1-3 小时 新手友好度 76/100
-
难度 2/5 1-3 小时 新手友好度 75/100
github/paste-markdown#129 · 2 个 reaction ·
-
bug
难度 1/5 1-3 小时 新手友好度 83/100
obsidianmd/obsidian-help#1164 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 82/100
richardcase/skills#26 ·
维护者通常 1 天内回复
-
难度 1/5 1 小时以内 新手友好度 88/100
维护者通常 1 天内回复