diff --git a/.changeset/csv-binary-encoding.md b/.changeset/csv-binary-encoding.md deleted file mode 100644 index 190fcdd..0000000 --- a/.changeset/csv-binary-encoding.md +++ /dev/null @@ -1,14 +0,0 @@ ---- -"javascript-excel": minor ---- - -`readCsv` can now tell whether an upload is text, within limits. All new options are off by default, so files 2.4 read are read the same way. - -- `rejectBinary: true` scans the decoded text once, before any record is parsed, and refuses a control character that text files do not contain with `FormatError` `CSV_BINARY_INPUT` (`details: { offset, byteOffset?, codePoint, encoding? }`, never file text). Refused: U+0000–U+0008, U+000E–U+001A, U+001C–U+001F and DEL; TAB, LF, CR, VT, FF and ESC are allowed. U+0080–U+009F are refused only in text decoded as Windows-1252, where they come from its undefined bytes. A PNG, PDF or zip renamed `.csv` is refused at its first control byte. -- `encoding: 'auto'`: a UTF-8 or UTF-16 BOM still wins; otherwise strict UTF-8, then strict Windows-1252 (0x81, 0x8D, 0x8F, 0x90 and 0x9D are not text). Bytes that are neither, or invalid after their BOM, throw `FormatError` `CSV_INVALID_ENCODING` (`details: { encodings, byteOffset? }`) instead of being replaced. UTF-16 without a BOM is not guessed. -- The result has a new `encoding` field for byte input: the encoding used, by its WHATWG name (`'utf-8'`, `'utf-16le'`, `'utf-16be'`, `'windows-1252'`, …). `importDataset` reports the one `'auto'` chose in `meta.encoding`. -- `maxInputBytes` refuses larger binary input with the same `LimitError` as `ReadLimits.maxInputBytes` for xlsx, and is validated the same way (a positive number; `null` is a `TypeError`); a `Blob` is checked by its size before it is read. It does not apply to string input. `importDataset` applies `limits.maxInputBytes` to CSV when it is given (CSV stays unlimited by default). -- `keepRows: false` (also for `parseCsv`) parses and checks every record, with the same limits, strict mode and warnings, but keeps none, so a check of a large upload holds only its bytes, its text and one record. -- `importDataset` takes `rejectBinary` for CSV input, and the worker client's `parseCsv` passes the new options through. With `limits.maxInputBytes` given, `importDataset` checks a `Blob`'s size before reading it, for every format. For uploads that must be CSV, pass `format: 'csv'`: with format detection a zip or xlsx input is read as a workbook and does not go through `rejectBinary`, which only checks that the input decodes to text (HTML, script or polyglot content passes). -- `readCsv` results for byte input gain an `encoding` key, so deep-equal comparisons of a whole result (`toEqual`) see one more key. -- `ExcelErrorCode` gains `CSV_BINARY_INPUT` and `CSV_INVALID_ENCODING`: an exhaustive `switch` with a `never` default needs the two new cases. diff --git a/.changeset/inspect.md b/.changeset/inspect.md deleted file mode 100644 index 20bd597..0000000 --- a/.changeset/inspect.md +++ /dev/null @@ -1,5 +0,0 @@ ---- -"javascript-excel": minor ---- - -New `inspect(input, { limits, signal })` in `javascript-excel/read` checks an `.xlsx`, `.xlsm`, `.xltx` or `.xltm` file part by part without building its cells, for servers and browsers that must accept or refuse an upload without reading it into the model. Under the same limits it refuses every file `read` refuses, with the same error class, code and details (zip and reader limits, encryption, CFB and other formats, `NOT_XLSX`, `XML_DTD_FORBIDDEN`, malformed XML in the parts `read` parses, every sheet to its last row), and it returns `read`'s `UNSUPPORTED_PART` warnings with their `partKinds` (VBA, macro sheets, external links, connections, OLE objects, query tables, …), the format, the worksheets with their cell counts (as `maxCells` counts them) and used ranges, and the counts of parts, inflated bytes, cells and shared strings. It also inflates every part `read` never opens (zip limits and CRC-32 apply) and searches its bytes for `` 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. diff --git a/apps/playground/package.json b/apps/playground/package.json index d1546e6..5a0dcfe 100644 --- a/apps/playground/package.json +++ b/apps/playground/package.json @@ -11,7 +11,7 @@ "test": "vitest run" }, "dependencies": { - "javascript-excel": "2.4.0" + "javascript-excel": "2.5.0" }, "devDependencies": { "happy-dom": "21.0.4", diff --git a/examples/node/package.json b/examples/node/package.json index 452f3eb..a9f3fc7 100644 --- a/examples/node/package.json +++ b/examples/node/package.json @@ -8,7 +8,7 @@ "check": "tsc -p tsconfig.json" }, "dependencies": { - "javascript-excel": "2.4.0" + "javascript-excel": "2.5.0" }, "devDependencies": { "@types/node": "22.20.5", diff --git a/examples/react/package.json b/examples/react/package.json index 3f455f7..ce73bbc 100644 --- a/examples/react/package.json +++ b/examples/react/package.json @@ -9,7 +9,7 @@ "check": "tsc -p tsconfig.json" }, "dependencies": { - "javascript-excel": "2.4.0", + "javascript-excel": "2.5.0", "react": "19.3.1", "react-dom": "19.3.1" }, diff --git a/examples/snippets/package.json b/examples/snippets/package.json index af45aef..5dc87d8 100644 --- a/examples/snippets/package.json +++ b/examples/snippets/package.json @@ -7,7 +7,7 @@ "check": "tsc -p tsconfig.json" }, "dependencies": { - "javascript-excel": "2.4.0" + "javascript-excel": "2.5.0" }, "devDependencies": { "@types/node": "22.20.5", diff --git a/examples/vanilla/package.json b/examples/vanilla/package.json index 751bc01..5e0c937 100644 --- a/examples/vanilla/package.json +++ b/examples/vanilla/package.json @@ -9,7 +9,7 @@ "check": "tsc -p tsconfig.json" }, "dependencies": { - "javascript-excel": "2.4.0" + "javascript-excel": "2.5.0" }, "devDependencies": { "typescript": "7.0.2", diff --git a/examples/vue/package.json b/examples/vue/package.json index 13f4e42..1146529 100644 --- a/examples/vue/package.json +++ b/examples/vue/package.json @@ -9,7 +9,7 @@ "check": "tsc -p tsconfig.json" }, "dependencies": { - "javascript-excel": "2.4.0", + "javascript-excel": "2.5.0", "vue": "3.5.45" }, "devDependencies": { diff --git a/package-lock.json b/package-lock.json index 245fa94..effbb5d 100644 --- a/package-lock.json +++ b/package-lock.json @@ -23,7 +23,7 @@ "name": "javascript-excel-playground", "version": "0.0.0", "dependencies": { - "javascript-excel": "2.4.0" + "javascript-excel": "2.5.0" }, "devDependencies": { "happy-dom": "21.0.4", @@ -35,7 +35,7 @@ "examples/node": { "name": "example-node", "dependencies": { - "javascript-excel": "2.4.0" + "javascript-excel": "2.5.0" }, "devDependencies": { "@types/node": "22.20.5", @@ -45,7 +45,7 @@ "examples/react": { "name": "example-react", "dependencies": { - "javascript-excel": "2.4.0", + "javascript-excel": "2.5.0", "react": "19.3.1", "react-dom": "19.3.1" }, @@ -59,7 +59,7 @@ "examples/snippets": { "name": "example-snippets", "dependencies": { - "javascript-excel": "2.4.0" + "javascript-excel": "2.5.0" }, "devDependencies": { "@types/node": "22.20.5", @@ -69,7 +69,7 @@ "examples/vanilla": { "name": "example-vanilla", "dependencies": { - "javascript-excel": "2.4.0" + "javascript-excel": "2.5.0" }, "devDependencies": { "typescript": "7.0.2", @@ -79,7 +79,7 @@ "examples/vue": { "name": "example-vue", "dependencies": { - "javascript-excel": "2.4.0", + "javascript-excel": "2.5.0", "vue": "3.5.45" }, "devDependencies": { @@ -3696,7 +3696,7 @@ } }, "packages/javascript-excel": { - "version": "2.4.0", + "version": "2.5.0", "license": "MIT", "devDependencies": { "@types/node": "22.20.5", diff --git a/packages/javascript-excel/CHANGELOG.md b/packages/javascript-excel/CHANGELOG.md index 13d4a9d..349c5c6 100644 --- a/packages/javascript-excel/CHANGELOG.md +++ b/packages/javascript-excel/CHANGELOG.md @@ -1,5 +1,24 @@ # javascript-excel +## 2.5.0 + +### Minor Changes + +- ad9bfee: `readCsv` can now tell whether an upload is text, within limits. All new options are off by default, so files 2.4 read are read the same way. + + - `rejectBinary: true` scans the decoded text once, before any record is parsed, and refuses a control character that text files do not contain with `FormatError` `CSV_BINARY_INPUT` (`details: { offset, byteOffset?, codePoint, encoding? }`, never file text). Refused: U+0000–U+0008, U+000E–U+001A, U+001C–U+001F and DEL; TAB, LF, CR, VT, FF and ESC are allowed. U+0080–U+009F are refused only in text decoded as Windows-1252, where they come from its undefined bytes. A PNG, PDF or zip renamed `.csv` is refused at its first control byte. + - `encoding: 'auto'`: a UTF-8 or UTF-16 BOM still wins; otherwise strict UTF-8, then strict Windows-1252 (0x81, 0x8D, 0x8F, 0x90 and 0x9D are not text). Bytes that are neither, or invalid after their BOM, throw `FormatError` `CSV_INVALID_ENCODING` (`details: { encodings, byteOffset? }`) instead of being replaced. UTF-16 without a BOM is not guessed. + - The result has a new `encoding` field for byte input: the encoding used, by its WHATWG name (`'utf-8'`, `'utf-16le'`, `'utf-16be'`, `'windows-1252'`, …). `importDataset` reports the one `'auto'` chose in `meta.encoding`. + - `maxInputBytes` refuses larger binary input with the same `LimitError` as `ReadLimits.maxInputBytes` for xlsx, and is validated the same way (a positive number; `null` is a `TypeError`); a `Blob` is checked by its size before it is read. It does not apply to string input. `importDataset` applies `limits.maxInputBytes` to CSV when it is given (CSV stays unlimited by default). + - `keepRows: false` (also for `parseCsv`) parses and checks every record, with the same limits, strict mode and warnings, but keeps none, so a check of a large upload holds only its bytes, its text and one record. + - `importDataset` takes `rejectBinary` for CSV input, and the worker client's `parseCsv` passes the new options through. With `limits.maxInputBytes` given, `importDataset` checks a `Blob`'s size before reading it, for every format. For uploads that must be CSV, pass `format: 'csv'`: with format detection a zip or xlsx input is read as a workbook and does not go through `rejectBinary`, which only checks that the input decodes to text (HTML, script or polyglot content passes). + - `readCsv` results for byte input gain an `encoding` key, so deep-equal comparisons of a whole result (`toEqual`) see one more key. + - `ExcelErrorCode` gains `CSV_BINARY_INPUT` and `CSV_INVALID_ENCODING`: an exhaustive `switch` with a `never` default needs the two new cases. +- 39e324a: New `inspect(input, { limits, signal })` in `javascript-excel/read` checks an `.xlsx`, `.xlsm`, `.xltx` or `.xltm` file part by part without building its cells, for servers and browsers that must accept or refuse an upload without reading it into the model. Under the same limits it refuses every file `read` refuses, with the same error class, code and details (zip and reader limits, encryption, CFB and other formats, `NOT_XLSX`, `XML_DTD_FORBIDDEN`, malformed XML in the parts `read` parses, every sheet to its last row), and it returns `read`'s `UNSUPPORTED_PART` warnings with their `partKinds` (VBA, macro sheets, external links, connections, OLE objects, query tables, …), the format, the worksheets with their cell counts (as `maxCells` counts them) and used ranges, and the counts of parts, inflated bytes, cells and shared strings. It also inflates every part `read` never opens (zip limits and CRC-32 apply) and searches its bytes for `` 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. + ## 2.4.0 ### Minor Changes diff --git a/packages/javascript-excel/package.json b/packages/javascript-excel/package.json index a809c18..509318a 100644 --- a/packages/javascript-excel/package.json +++ b/packages/javascript-excel/package.json @@ -1,6 +1,6 @@ { "name": "javascript-excel", - "version": "2.4.0", + "version": "2.5.0", "private": false, "description": "Read and write .xlsx and .csv files in browsers, Web Workers and Node. 2.0 is a from-scratch rewrite in progress.", "keywords": [ diff --git a/packages/javascript-excel/src/index.ts b/packages/javascript-excel/src/index.ts index b0004c2..e003b9e 100644 --- a/packages/javascript-excel/src/index.ts +++ b/packages/javascript-excel/src/index.ts @@ -76,4 +76,4 @@ export { decodeCell, decodeCol, decodeRange, encodeCell, encodeCol, encodeRange, export type { CellAddress, RangeAddress } from "./address"; /** Package version. Set from package.json by `npm run version-packages` (scripts/sync-version.mjs); a unit test checks it. */ -export const VERSION = "2.4.0"; +export const VERSION = "2.5.0";