Skip to content

fix(d1): don't corrupt literal \n in export when a value also has a real newline - #8699

Open
Jeremiah-D wants to merge 1 commit into
cloudflare:mainfrom
Jeremiah-D:fix/8678-d1-export-quote
Open

Jeremiah-D wants to merge 1 commit into
cloudflare:mainfrom
Jeremiah-D:fix/8678-d1-export-quote

Conversation

@Jeremiah-D

Copy link
Copy Markdown

Fixes #8678.

Exporting a row whose value contains both a real newline and a literal \n corrupts the value: a<LF>b<\n>c comes back as a<LF>b<LF>c on import, because quote() in src/workerd/server/d1/d1.js always escapes newlines as \n without checking whether the value already contains that sequence.

This ports the collision check from SQLite's shell.c.in (same approach as Miniflare's fix in workers-sdk#15334): unusedEscape() tries \n, then \012, then (\n0), (\n1), … and takes the first escape not present in the value, with the same ladder on the CR side (\r, \015, (\r0), …).

Verified with a standalone node harness (20 cases: the reporter's example now round-trips, golden rows match byte-for-byte, triple collisions escalate as expected) and against real SQLite end to end (4 rows, all identical after import). I couldn't run wd-test locally — no bazel here — so that's left for CI.

…eal newline

Signed-off-by: Jeremiah-D <235112616+Jeremiah-D@users.noreply.github.com>
@Jeremiah-D
Jeremiah-D requested review from a team as code owners November 20, 2026 00:01
Copilot AI balanced review requested due to automatic review settings November 20, 2026 00:01

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

@github-actions

Copy link
Copy Markdown


Thank you for your submission, we really appreciate it. Like many open-source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution. You can sign the CLA by just posting a Pull Request Comment same as the below format.


I have read the CLA Document and I hereby sign the CLA


You can retrigger this bot by commenting recheck in this Pull Request. Posted by the CLA Assistant Lite bot.

@clanky-the-clanker

Copy link
Copy Markdown

This pull request was not reviewed automatically because its author does not have write access to this repository. A maintainer with write access can start a review by commenting clanky review (or clanker review or @clanky-the-clanker review), optionally followed by instructions (e.g. clanky review focus on the retry logic).

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.

D1 export: quote() in d1.js turns a literal \n into a newline when the value also has a real newline

2 participants