Skip to content

fix(io): honor CRLF option when saving text files in save() - #9187

Open
Pcmhacker-piro wants to merge 1 commit into
processing:mainfrom
Pcmhacker-piro:fix/save-crlf-text
Open

Pcmhacker-piro wants to merge 1 commit into
processing:mainfrom
Pcmhacker-piro:fix/save-crlf-text

Conversation

@Pcmhacker-piro

Copy link
Copy Markdown
Contributor

Description

Resolves #9141

Root Cause

When calling save() on text / string arrays:

  1. save() delegated to fn.saveStrings(args[0], args[1], args[2]) without passing args[3] (isCRLF), discarding the CRLF option when passed as save(data, 'filename', 'txt', true).
  2. When the extension is included in the filename parameter (e.g. save(data, 'filename.txt', true) or saveStrings(data, 'filename.txt', true)), _checkFileExtension extracts the 'txt' extension, and the boolean flag was passed as args[2]. saveStrings(list, filename, extension, isCRLF) received extension = true and isCRLF = undefined, defaulting to LF (\n).

Changes

  • Updated fn.save() to forward args[3] to fn.saveStrings(args[0], args[1], args[2], args[3]).
  • In fn.saveStrings(), check if (typeof extension === 'boolean') { isCRLF = extension; extension = undefined; } so passing (list, 'filename.txt', true) properly sets isCRLF = true.
  • Added unit tests in test/unit/io/files.js verifying CRLF output for both save() (4-argument and 3-argument signatures) and saveStrings() (extension omitted).

Proof & Verification

Real Terminal Video (asciinema recording)

Real Terminal Demo

Unit Tests Passing

Unit Tests Output

PR Checklist

  • npm run lint passes
  • npx vitest run test/unit/io/files.js passes (all 21 unit tests pass)
  • No breaking API changes introduced

@Pcmhacker-piro

Copy link
Copy Markdown
Contributor Author

Hi @ksen0 @limzykenneth, could you please review this PR when you get a chance? It resolves #9141 by ensuring the CRLF parameter is respected in save() and saveStrings(). Real terminal asciinema recording, passing unit tests, and lint checks have been verified and attached. Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[p5.js 2.0+ Bug Report]: save() ignores the CRLF option when saving text files

2 participants