DataTable render crashes with StringIndexError on multibyte cell text #36
Labels
No labels
bug
documentation
duplicate
enhancement
good first issue
help wanted
invalid
question
windows
wontfix
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
kahliburke/Tachikoma.jl#36
Loading…
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Summary
DataTable.render(and the pagedrender.jlequivalent) truncates overlong cell text by byte-indexing aString, but Julia strings index by byte whilelength/availcount characters. When a cell contains multibyte UTF-8 (e.g. em-dash—, 3 bytes) the slice boundary can land mid-character and throwStringIndexError.Stack trace (reported via Kaimon)
Cause
src/widgets/datatable.jl:534andsrc/paged/render.jl:124:cell_text[1:avail-1]treatsavail-1as a byte offset.Fix
Use
first(s, n), which counts characters and respects UTF-8 boundaries:Reported downstream in kahliburke/Kaimon.jl#29.
Full scope: same byte-index-vs-character bug found at 6 sites
A sweep for the truncate-by-byte pattern (
length-guardedStringslice with a width/char count used as a byte index) turned up the same class of bug in several widgets. All fixed by switching to character-safefirst(s, n):src/widgets/datatable.jl:534src/paged/render.jl:124src/widgets/datatable.jl:435src/paged/render.jl:27src/paged/render.jl:279src/widgets/table.jl:112src/widgets/barchart.jl:68src/app.jl:669Editor widgets (
codeeditor.jl,textarea.jl) were checked and are not affected — their lines areVector{Char}, so the slices are already character-indexed.layout.jlconstraint deserialization is internal ASCII and safe.Tests
Regression tests added that sweep buffer/column widths so the truncation boundary lands at every byte offset within a multibyte run (em-dash = 3 bytes), guaranteeing the mid-character cut is exercised:
test/test_widgets_extended.jl— DataTable cells + headerstest/test_paged_datatable.jl— paged cells, headers, error overlaytest/test_widgets_coverage.jl— Table cellstest/test_core.jl— BarChart labelsEach test was verified to fail on the pre-fix code and pass after. Full suite: 5074/5074 passing.
Check your discord sometimes too 😄
or do we have to talk here from now on?
I'm doing so much work now!
learnt a lot
@kahliburke Dr KB !
Fixed in v2.3.0 (released).
Root cause was truncating overlong text by byte-indexing a
Stringwhile the length guard counts characters — so a cut inside a multibyte UTF-8 char (e.g. the 3-byte em-dash) threwStringIndexError. Fixed by switching to character-safefirst(s, n)at every truncation site:DataTable(cell + header),PagedDataTable(cell + header + error overlay),Table,BarChart, and the export-modal font name. Editor widgets (codeeditor/textarea) operate onVector{Char}and were unaffected.Regression tests added that sweep buffer/column widths so the truncation boundary lands at every byte offset within a multibyte run (each verified to fail before the fix, pass after).
f180230)