-
-
Notifications
You must be signed in to change notification settings - Fork 3.7k
Description
Most appropriate sub-area of p5.js?
- Accessibility
- Color
- Core/Environment/Rendering
- Data
- DOM
- Events
- Image
- IO
- Math
- Typography
- Utilities
- WebGL
- Build process
- Unit testing
- Internationalization
- Friendly errors
- Other (specify if possible)
p5.js version
2.x (main)
Web browser and version
any
Operating system
any
Steps to reproduce this
saveTable() wraps values containing commas in quotes (that got fixed in an old PR), but it never escapes " characters inside those values. So any cell with both a comma and a quote produces malformed CSV.
function setup() {
let t = new p5.Table();
t.addColumn('name');
t.addColumn('note');
let r = t.addRow();
r.setString('name', 'thing');
r.setString('note', 'He said "yes, go ahead"');
saveTable(t, 'out.csv');
}
Output:
name,note
thing,"He said "yes, go ahead""
That middle " is unescaped. Most CSV parsers (Excel, Python csv, loadTable itself) will choke on it or misread the row.
RFC 4180 says inner quotes must be doubled. Should be:
name,note
thing,"He said ""yes, go ahead"""
Also: headers with commas or quotes are never escaped either. And a newline inside a value will silently break row boundaries with no quoting at all.
loadTable handles all of this correctly on the way in. So load a valid CSV → save it back → file is now broken. Classic round-trip corruption.
The fix is one line per write call: escape " as "" before wrapping, and trigger quoting on " or \n too, not just ,.