Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions .changeset/package-scan-active-content.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
"javascript-excel": minor
---

`read` (and `importDataset`, which passes read warnings on) now walks the whole relationship graph of the package and reports more content it does not read as `UNSUPPORTED_PART`, with six new `partKind` values: `'activeX'` (ActiveX controls), `'embeddedPackage'` (a `package` relationship, such as a `.docx` embedded under `xl/embeddings/`), `'customUI'` (a ribbon customisation: the root `ui/extensibility` relationship of Office 2007 or 2010), `'webExtension'` (Office web add-ins), `'invalidPartName'` (a zip entry name, relationship target or Override PartName OPC forbids: `%2F` or `%5C` in a segment, a percent-encoded dot segment, a segment ending in a dot, a target naming a relationships part or `[Content_Types].xml`, a target or PartName over 196,605 characters, which is not resolved; or a `<Relationship>` without `Id` or `Target`, which the model still ignores) and `'unreferencedPart'` (a part no relationship reaches, such as a `vbaProject.bin` or an executable placed in the zip). The last two come as one warning each, with every name in a new `parts` field on the warning (bounded by `maxEntries`). Nothing is exempt by name: discarded parts Office 2007/2010 left under `[trash]/` are reported too; a consumer that accepts them can check that every name in `parts` starts with `[trash]/`. The scan also finds `'oleObject'`, `'vbaProject'` (now also attached toolbars and VBA signatures), `'externalLink'`, `'connections'`, `'queryTable'` and `'macrosheet'` where they were not reported before: under a drawing, under a table, or on a sheet left out by the `sheets` option. Excel 4 macro sheets with Microsoft's `xlMacrosheet` and `xlIntlMacrosheet` relationship types are now reported as `'macrosheet'`. Relationship types are compared case-insensitively, and a part with the content type of an ActiveX control, OLE object, VBA project, macro sheet, web add-in or embedded Office file (documents, templates, add-ins, slides) is reported as that kind whatever relationship reaches it; equivalent Overrides in `[Content_Types].xml` are all checked. Drawings, images, comments and the other passive kinds are reported as before. Every relationships part in the zip is classified, also one whose owner nothing reaches. The scan reads only relationships parts, within the existing zip and XML limits, never inflates the parts it reports, and consults the signal throughout; a relationships part that is not well-formed XML is reported as unreferenced instead of failing the read. Existing warnings keep their shape; a `switch` over `ExcelPartKind` needs a `default` branch, as documented. The test corpus (files from LibreOffice and openpyxl, and every file of the conformance corpus this library writes) gives no new warnings.

Behaviour changes against 2.4.0: part names are compared in OPC canonical form (percent-escapes decoded once, as UTF-8, on both sides; `%2F`, `%5C`, `%25` and invalid bytes kept encoded), so percent-encoded zip entry names are now found where 2.4.0 reported `MISSING_PART` or `NOT_XLSX`, while a target matched to an entry only because 2.4.0 decoded the target and not the entry name (a literal `%` spelled differently on the two sides) no longer matches. Two zip entries with equivalent names (for example `a b` and `a%20b`) now throw `ZIP_INVALID`, as names that differ only in case already did. Because the scan parses every relationships part in the zip, a DTD or an over-deep XML in one of them (also under a sheet that is not read, or in an orphan relationships part) now throws `XML_DTD_FORBIDDEN` or `LIMIT_EXCEEDED`; 2.4.0 read such a file. A relationship target or Override PartName longer than 196,605 characters is not resolved and is reported as `'invalidPartName'`; the length is checked before dot segments are resolved, so a part reachable only through such a padded target (for example 200 KB of `./` before `worksheets/sheet1.xml`) is now missing for `read`, where 2.4.0 read it.
20 changes: 15 additions & 5 deletions docs/api.md

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion packages/javascript-excel/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ const cell = exact.workbook.sheets[0]?.rows[0]?.[0];
console.log(cell?.type, cell?.value, cell?.rawText); // "number" 50.3 "50.30"
```

Damage the reader can recover from comes back as `warnings`. `isDataLossWarning(w)` tells the ones where data was lost (a cell skipped, rows cut, a part missing, comments or charts not read; `partKind` names the part) from informational ones; the warning cap (`limits.maxWarnings`, default 1,000) drops only informational warnings, so filtering `warnings` with it is enough to refuse a damaged file.
Damage the reader can recover from comes back as `warnings`. `isDataLossWarning(w)` tells the ones where data was lost (a cell skipped, rows cut, a part missing, comments or charts not read; `partKind` names the part, including ActiveX controls, embedded files, customUI, web add-ins and parts no relationship reaches, wherever they sit in the package) from informational ones; the warning cap (`limits.maxWarnings`, default 1,000) drops only informational warnings, so filtering `warnings` with it is enough to refuse a damaged file.

## CSV

Expand Down
3 changes: 2 additions & 1 deletion packages/javascript-excel/src/internal/read/context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,12 +69,13 @@ export class ReadContext {
* dropped warning adds WARNINGS_TRUNCATED at that point, as in 2.0.0; its
* `dropped` counts grow until the read ends.
*/
warn(code: ExcelWarningCode, message: string, where?: { part?: string; sheet?: string; ref?: string; partKind?: ExcelPartKind }): void {
warn(code: ExcelWarningCode, message: string, where?: { part?: string; sheet?: string; ref?: string; partKind?: ExcelPartKind; parts?: string[] }): void {
const w: ExcelWarning = { code, message };
if (where?.part !== undefined) w.part = where.part;
if (where?.sheet !== undefined) w.sheet = where.sheet;
if (where?.ref !== undefined) w.ref = where.ref;
if (where?.partKind !== undefined) w.partKind = where.partKind;
if (where?.parts !== undefined) w.parts = where.parts;
const kept = this.cap.add(w, (dropped) => {
const t: ExcelWarning = { code: "WARNINGS_TRUNCATED", message: `More than maxWarnings (${this.limits.maxWarnings}) warnings; later ones were dropped.`, dropped };
this.cap.warnings.push(t);
Expand Down
Loading