Hacktoberfest 2026: the issues maintainers tagged for October, open and beginner-friendly. Browse Hacktoberfest issues

parseAttributeValue 将单元格坐标 "E1" 误判为科学计数法并转成 null,导致属性值丢失

Open Beginner friendly
#888 2 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 2 days

Nobody has claimed this yet.

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
65/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Active
Tech stack
javascript, node.js
Domain
data

Research direction

Start with the reproduction: new XMLParser({ parseAttributeValue: true, ignoreAttributes: false }) parsing <hyperlink ref="E1"/> returns null for ref, while F1 and B5 survive. Find where attribute values are converted to numbers and how numberParseOptions.eNotation is applied, since the E1 case is treated as scientific notation. Done means E1 stays the string "E1" by default, other numeric attributes still convert, and a test covers the E1/E10 cases with eNotation on and off.

Written by the indexing model from the issue text.

Description

bug
背景与实际问题

我在开发一个 Android 离线 WebView 里的 .xlsx 只读预览/编辑器,底层用 fast-xml-parser 解析原始 worksheet XML。

xlsx 里的单元格坐标(如 E1)会出现在工作表超链接的属性上:

<hyperlink ref="E1" location="Sheet2!A1"/>
  • ref="E1" —— 这个超链接贴在哪个单元格(左上角坐标,随所在位置变化,可能是 A1/B5/E1/F1…)
  • location="Sheet2!A1" —— 点击后跳转的目标

也就是说,E1 在这里只是一个普通的单元格地址字符串,既不是整数、也不是科学计数法,它本应被当作字符串原样保留。

问题

开启 parseAttributeValue: true 后,fast-xml-parser 会把属性值自动转成数字。它对 E1 的判定是:看起来像科学计数法 E1(= 1×10¹),尝试转换后得到 null,结果把整个坐标属性吃掉了:

const { XMLParser } = require('fast-xml-parser') // 4.5.7 / 4.x

const p = new XMLParser({
  ignoreAttributes: false,
  attributeNamePrefix: '@_',
  parseAttributeValue: true,
  trimValues: true,
})

p.parse('<hyperlink ref="E1" location="Sheet2!A1"/>')

实际输出:

{ "hyperlink": { "@_ref": null, "@_location": "Sheet2!A1" } }

期望输出(或至少不能丢原值):

{ "hyperlink": { "@_ref": "E1", "@_location": "Sheet2!A1" } }

对比:同一份文件里 ref="F1"、ref="B5" 都能正常保留为字符串,唯独 E1(以及任何形如 字母+E+两位数字 的值)被转成 null。在我这个 xlsx 里,有两张表的返回链接 ref="E1" 因此整条丢失、格子里点不动;而另一张表是 ref="F1" 就正常。

影响面

E1/E2/E10… 这类单元格坐标在 OOXML(表格、图表引用、定义名称等)里极常见。凡是开启 parseAttributeValue 的解析场景,只要出现这类坐标,就会被静默转成 null,造成数据丢失,且很难排查。

临时规避
numberParseOptions: { eNotation: false }

设置后 E1 会被保留为字符串,其它数字属性仍照常转换。

关于 eNotation

这个行为由 numberParseOptions.eNotation(默认 true)控制。默认开启时,很多纯粹是"字符串"的标识值只要长得像科学计数法,就会被当成数字处理——对 XML 这种以字符串属性为主的数据格式,风险较高,且转换失败后直接变 null(而非保留原字符串),进一步放大了问题。

环境
  • fast-xml-parser: 4.5.0(本地实测 4.5.7 同样复现)
  • Node / 浏览器均复现

(说明:我这边只用到解析能力,不确定在此之外是否有其它依赖;如已存在同类 issue,烦请合并,谢谢。)

Dominant language
JavaScript
Stars
3.1k
Forks
398
Avg merge
2d 14h
Merged PRs (30d)
2

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from NaturalIntelligence/fast-xml-parser

All issues in NaturalIntelligence/fast-xml-parser

Similar issues

More JavaScript issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.