processing / processing/p5.js

[p5.js 2.0 Bug Report]: saveTable() doesn't escape double quotes in CSV, round-trip corrupts data

Open
#8,551 13 comments 0 reactions 1 assignee View on GitHub

@avinxshKD is already working on this.

Since Mar 11, 2026.

Area:IO p5.js 2.0+
Dominant language
JavaScript
Stars
24k
Forks
3.8k
Avg merge
3d 16h
Merged PRs (30d)
25

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 ,.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.