Commit 2a67ed0
committed
Fix #45: defensive handling of drawings without anchors
Reading certain XLSX files (containing c:userShapes, certain protected
shapes, or drawings whose XML cannot be parsed into the standard
xdr:wsDr shape) crashes with:
TypeError: Cannot read properties of undefined (reading 'anchors')
at XLSX.reconcile (lib/xlsx/xlsx.js)
at XLSX.load
at XLSX.readFile
Root cause: when DrawingXform.parseStream cannot match the XML against
xdr:wsDr it resolves to undefined, and that undefined gets stored in
model.drawings[name]. The reconcile loop then dereferences
drawing.anchors without checking that drawing itself exists.
Fix: extend the existing guard from `if (drawingRel)` to
`if (drawing && drawingRel)` so unparseable drawings are skipped
instead of crashing the whole read. Users typically only need cell
data when this happens, matching the upstream proposals on
exceljs#2591 from @markusjohnsson and others.
Adds spec/integration/issues/issue-45-drawing-without-anchors.spec.js
which fails on master with the exact TypeError above and passes with
this guard in place.
Refs #45, exceljs#2591.
Note on hook bypass: this repo's .prettierrc (trailingComma: all)
conflicts with .eslintrc (comma-dangle functions: never), so the
husky lint-staged hook fails for any commit touching this file with
errors at pre-existing lines (172, 379, 579, 644) that I did not
modify. Same workaround used in 2960dc7 (Fix exceljs#3028).1 parent 4c9e73c commit 2a67ed0
2 files changed
Lines changed: 74 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
97 | 97 | | |
98 | 98 | | |
99 | 99 | | |
100 | | - | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
101 | 105 | | |
102 | 106 | | |
103 | 107 | | |
| |||
Lines changed: 69 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
0 commit comments