mirror of
https://github.com/storytold/gridcraft.git
synced 2026-12-05 23:00:06 +00:00
* XLSX: per-child allowances for streamed shared strings and Python scripts; warnings for repeated and out-of-order cells The streaming parser that reads the shared-string table and the Python part is told which children each streamed element may hold, and how many: a shared string one `phoneticPr` and its text (`t`, `r`, `rPh`) without a count; a `pythonScript` one `code`. An unknown name is admitted once, for at most MAX_UNLISTED_CHILD_NAMES names. A child past its allowance is dropped with its subtree and counted. Inside a streamed element the element cap no longer fails the part: the element that would pass it is dropped and counted, and so is each element holding it up to the streamed element's own child, which is lost whole. A child lost at the cap gives back its place in its name's allowance, so a later child of that name can still be read. Later children that fit, and later strings and scripts, are still read (main kept only what came before). When the cap was already reached before the streamed element that holds a child being dropped began (the innermost open one, so also one that begins inside another), nothing in it can be kept, and the part fails as on main, at the first element that closes inside it. A streamed element that holds no element (`<si/>`, `<si></si>`, or one holding only whitespace) is still handed out with the cap full, as on main: the cap bounds the elements the parser holds, and it holds none. The streamed element is marked cut only when the child it lost has a listed name, and the mark records which listed names it lost (a bit per name in `El::cut`, read with `El::lost`); an unknown element holds nothing the reader reads. An unknown name whose child is dropped at the cap gives back its place among the unknown names the element may hold. A shared string that lost text (a `t` or a run) at the cap keeps the children that fit, with a warning, and drops its phonetic runs, since their offsets point into the text as the file held it, and its phonetic properties, which would otherwise be filed under the shortened text and take the place of an intact string's reading of that text. The warning counts every phonetic run dropped from a string that lost text, damaged runs and those of a string that counts as missing included, and the strings whose phonetic properties went. One that lost only phonetic parts (an `rPh` or its `phoneticPr`) keeps its text and its other runs. A string that lost text and kept none (an empty run kept before the lost text holds none) counts as a missing string, as on main: its cells are empty, the existing warning about missing shared strings is given, and the strings after it keep their indexes (the table holds an Option per string). A Python script that lost its code at the cap and kept no code after it (none, or an empty one) counts as missing code: a cell naming it keeps its cached value without Python code, as main does for missing code. Unknown children of a script that fit are left out, as on main, and a warning now counts them, also when the part turns out damaged after them, as the shared-string reader does. GridCraft places each worksheet cell where its address says, as on main, a later cell read again where an earlier one was; a picture cell keeps its picture, and an empty cell leaves a Python spill value. A warning now counts cells that repeat an address and rows whose properties are read again over ones already read (the later ones kept); another counts cells out of column order or in another row's element. A cell of a row element's own row at a column held already, by that element or by the elements for the same row right before it, is a repeat, whatever the reader stored for it (a bitmap of the columns read, cleared when a row element of another row number begins, up to the highest word the elements before it touched). Otherwise a repeat is seen at the furthest position read so far, or before it where a cell, a cell picture or a spill value is stored, so a cell that repeats one the reader stores nothing for (a blank cell without a style, a value inside another formula's array) is not counted as a repeat when an element for another row sits between the two copies, or one of them sits in another row's element, unless it is at the furthest position; it is counted as out of place when it sits in another row's element or out of column order. A cell counted as a repeat is not also counted there; any other cell is, when it names another row than the row element it sits in, whatever its column, or when its column is not to the right of the rightmost column among the cells read before it in that element. Only cells not past the furthest one are looked up. Cell text longer than MAX_CELL_CHARS (UTF-16 units) is kept whole, and a warning per sheet counts the long texts read: shared and inline strings, the cached text of a formula that doesn't parse, and spill values, but not a picture's fallback, a value inside another formula's array, or a parsing formula's cached result. The count is taken as each cell is read, so a long text that a later cell replaces is still counted. The length is decided from the byte length where that is enough (up to the limit in bytes it is within it, past three times the limit it is over) and otherwise by counting bytes, not by decoding characters. MAX_CELL_CHARS joins MAX_ROWS and MAX_COLS in gridcraft_core::addr, and MAX_TEXT_CHARS in gridcraft_core::value is now derived from it; docs/file-format-parity.md records the change. Tests: crates/xlsx/src/tests/limits.rs (allowances at and past the limit, unknown names, the cap at its edge and inside a run, a string that loses only an unknown element at the cap, a string that lost all its text at the cap, or kept only an empty run, a string that lost text and had phonetic runs, a string that lost all its text and had phonetic runs, one that lost text and kept its phonetic properties, before and after an intact string with the same text, through a save, one that lost only a phonetic run or its phonetic properties, one with empty text that lost only a phonetic run, a string at the cap and one past it, an empty `t` lost at the cap taken as lost text by name, run formatting and an unknown element inside a run left out without a warning, repeated cells and rows, repeats of cells the reader stores nothing for, in one row element, in elements for the same row in a row, and after another row's element, every sequence of up to three cells over two columns and two rows split across up to three row elements against a plain reading of the rule, out-of-order cells left of the rightmost one, cells in columns CV and XFD of two rows in a row, long text at the limit and one past it, a shared string over the limit in bytes but not in UTF-16 units, 20,000 repeats of a cell using a long shared string), richdata_tests.rs (picture cells with repeats, through a save), the parser's tests in xml.rs (a string inside another that begins with the cap full, strings holding no element handed out with the cap full, one under it and three in a row, which listed children a string lost at the cap, an unknown name dropped at the cap freeing its place) and python_part.rs, and crates/engine/src/tests/python_files.rs (long spilled text, repeats in a spill, code dropped at the cap, an empty script with the cap full, a second code taken when the first is dropped at the cap, an empty code after one dropped at the cap, a second code crossing the cap after a kept one, a script without code whose unknown element crosses the cap, a second code, through a save, unknown children of scripts counted in one warning, none, and in a part damaged after them). Co-Authored-By: Claude Fable 5.1 <[email protected]> Co-Authored-By: Claude Opus 5.5 <[email protected]> * Preserve text boundaries when shared-string runs are dropped --------- Co-authored-by: Claude Fable 5.1 <[email protected]> Co-authored-by: FredApps <[email protected]>