Repository navigation
fix(onlyoffice): a decimal typed into a CSV keeps the file's comma - #121
Conversation
In the Turkish or the German editor a decimal comma typed is a number, and Docs 9.4 saves every number with a point and up to 17 significant digits: `3,5` typed over as `4,5` in a semicolon file went to the file as `4.5`, `1,1` as `1.1000000000000001`, in a column of `3,5` and `1250,75` that KeepCSV kept as they were (they are text to ONLYOFFICE). KeepCSV now writes such a number with a decimal comma in the cells somebody typed or added, on evidence only: a file not separated by commas; a column of the file with decimal commas and no point, exponent or comma-grouped thousands; a decimal comma of that column kept byte for byte in a row lined up with the file's (the column did not move); and a value the file holds in none of its cells (a number that moved there is the file's own). 16 or 17 digits that are exactly %.17g become the shortest decimal of the double. csvKeepCheck accepts the comma only in those columns, and only for the same number. Measured on Docs 9.4.0.1 in Turkish, English and German; the saved bytes are in csv_keep_comma_test.go. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
8b24ef4 to
7c54b31
Compare
|
Thanks Berk, this is a careful fix. I reviewed it against our tree for 0.57.1: it applies cleanly on 0.57.0, every test passes (with I re-measured on Docs 9.4.0.1 (tr-TR and de-DE) and your vectors hold. Grouped whole numbers ( It will ship in 0.57.1 with your authorship, and this pull request will show as merged when that release lands. On top of it we added:
For later: a Turkish or German money column holding a grouped whole number ( Cost: |
What
A decimal typed into a CSV in ONLYOFFICE lost the file's decimal comma. KeepCSV (#88) keeps the cells nobody touched; the cell somebody edited was written as ONLYOFFICE saved it, and for a decimal that is a point.
Seen on a production install (filex 0.56.3, Docs 9.4.0-129, editor in Turkish): a semicolon file with a
Tutarcolumn of3,5/1250,75/0,25.3,5typed over as4,5; every untouched cell came back byte for byte, the edited one as4.5.Reproduced and measured locally on
onlyoffice/documentserver:9.4.0.1(JWT off, its defaults; the CSV opened with UTF-8 and its delimiter indocument.optionsas filex does; cells typed through the cell name box; the bytes are the file of the status 2 callback):tr-TR)en-US)de-DE)4,54.5"4,5"(text)4.51.250,751250.751250.751,11.100000000000000112345678,12345612345678.1234559991234567812345612345678.1234559990,0000019.9999999999999995e-074,5%4.50%4.50%4.54.May4.504.Mai-4.5-4.5-4.5-4.5In a comma-decimal language the typed decimal is a number, and the writer prints numbers with a point and
%.17g. Untouched3,5cells are text to ONLYOFFICE in every language and come back as they were - so a column ends up mixed. The full table is indocs/CONTRIBUTING.md.How
officesave/csv_keep.go(rebased on v0.57.0, so it covers both editors'SaveCSV): in a record somebody changed, and in a row they added, a saved cell that is a number with a point and digits (-?\d+\.\d+, nothing else) is written with a decimal comma - only on evidence:3,5,1.250,75) and none with a point or an exponent (3.5,1.250,1e3) or comma-grouped thousands (1,250,000);1,250alone is no evidence (the English editor reads it as 1250);csvMovedNumbers, by float64 value). A column deleted, added or moved, or cells shifted along a row, put the file's own numbers at the column's place; those keep their point. Checked only when a comma was actually written: the kept file is then written a second time without the moved values.16 or 17 significant digits that are exactly
%.17gof their double become the shortest decimal of the same double (1.1000000000000001->1,1), which is what was typed; any other text keeps its digits; more than 17 digits is no number the writer printed and gets nothing. An exponent, a percent, a date or a whole number is written as before.P1 / P2.
csvSameis unchanged: this is not a "same value" rule, it writes the save's own value in the column's way of writing it.csvKeepCheckaccepts a comma cell only in a column the evidence named, only in the one spelling the writer produces, and only when it reads back (comma as the decimal mark) as the saved number. Anything else still falls back toRewriteCSV.Why not the editor's language. The save carries no language,
4,5typed in Turkish and4.5typed in English save the same4.5, and people in both may edit one file. Storing the opener's locale would need a column onoffice_sessionsand would still be wrong for a co-edited session. So the column decides, whoever typed. Documented consequence: an English user's4.5(or a Turkish user's apostrophe text'4.5) in such a column is written4,5too.CSVKept.Commascounts these cells; the debug lineonlyoffice callback: CSV cells keptgainscommas.Tests
officesave/csv_keep_comma_test.go, new (measured vectors of the report inofficesavetest/docs94_comma.go; the callback case inonlyoffice/callback_csv_measured_test.go):0,25->1,1and adds a row with2,75, throughKeepCSVand through the callback;1.5moved,1,250thousands,1,250,000, a typed value the file holds elsewhere;appendCSVCommaDecimal,csvCommaNumber,csvThousands,csvPointNumbertables, andcsvKeepCheckwith and without comma columns.FuzzKeepCSVseeds the new cases; its read-back property (sameRow) accepts the comma spelling,csvKeepCheckstays the strict one.Checked
gofmt,go vet ./...,go build ./...clean;go test ./internal/officesave/... ./internal/onlyoffice/ok, also with-race.FuzzKeepCSV120 s + 2 x 90 s before the rebase, 90 s after: pass.BenchmarkKeepCSV(500,004 records / 54 MB, M-series): 0.59 s onmain(v0.57.0), 0.63 s here (+7%), allocations unchanged (126 MB). The column classification rides on the index pass;csvPointNumberallocates nothing.BenchmarkKeepCSV_LiningUpunchanged.node scripts/check-links.mjs: all resolve.check-doc-anchors.mjsnot run locally (needs the docs-site install); CI runs it.TestDownloadLink_AnotherTenantsHostandTestAdminShares_RowsCarryTheCanonicalURLfail ininternal/api/handlerson my machine, as they did for fix(onlyoffice): a CSV saved from ONLYOFFICE keeps the cells nobody changed #88 on an untouched checkout.1,250thousands, >17-digit text and an allocation in the classifier, the second found exponents and1.5slipping past the moved-number check (it was by spelling, now by value). Each is a test case now.Not done
e2e/tests/199-csv-onlyoffice.spec.tsis unchanged (its edit is a whole number). A fixture that would cover this: the release-gate file with a3,5column, edited to4,5with the editor in Turkish.🤖 Generated with Claude Code