D1 export: `quote()` in d1.js turns a literal `\n` into a newline when the value also has a real newline
メンテナーはふだん 1 日以内に返信
評価
- 難易度
- 2/5
- 見積もり時間
- 1〜3時間
- 初心者へのやさしさ
- 85/100
- issue の種類
- バグ
- 明瞭さ
- 明確に書かれている
- 活発さ
- 活発
- 技術スタック
- javascript
調査の方向性
src/workerd/server/d1/d1.js を読み、quote() をたどって、改行と復帰のエスケープ方法がどのように選ばれるかを確認してください。shell.c.in と Miniflare の dumpSql.ts について説明されている衝突処理を比較し、その後 d1-export-test.js を調べてください。実際の改行とリテラルの \n の両方を含むエクスポートケース(および対応する復帰のケース)を追加し、インポート時にエクスポートが両方の値を保持することを確認してください。
索引モデルが issue の本文から書いたものです。
説明
The new built-in D1 (src/workerd/server/d1/d1.js, from #8486) has the same export escaping bug that was reported against D1 in cloudflare/workers-sdk#9042 (internal ticket CFSQL-1294). Remote D1 has since fixed it, and cloudflare/workers-sdk#15334 fixes it in Miniflare's dumpSql.ts. But cloudflare/workers-sdk#16955 replaces dumpSql.ts with this code, so once that lands wrangler d1 export --local will have the bug again.
The problem is in quote(), which uses the same logic as the old dumpSql.ts (where this reproduces on wrangler 4.154.0):
let out = `'${text.replace(/'|(\n)|(\r)/g, (_, n, r) => {
if (n) return ((lf = true), '\\n');
if (r) return ((cr = true), '\\r');
return "''";
})}'`;
if (cr) out = `replace(${out},'\\r',char(13))`;
if (lf) out = `replace(${out},'\\n',char(10))`;
Each real newline becomes the two characters \n, but a \n already in the value is left as-is. The replace() wrapper can't tell them apart, so on import both turn into newlines.
Example: the value 'a' || char(10) || 'b\nc' (hex 610A625C6E63) exports as
replace('a\nb\nc','\n',char(10))
which reads back as 610A620A63. The backslash-n is gone. \r has the same problem.
The comment says this follows shell.c.in's output_quoted_escaped_string, but the shell version first checks whether the value already contains the escape and picks one it doesn't (\n, then \012, then (\n0), (\n1), ...). Remote D1 export does the same thing now, e.g. the value above exports from remote as:
replace('a\012b\nc','\012',char(10))
So the fix is probably to port that collision check, like cloudflare/workers-sdk#15334 does for Miniflare. The export test in d1-export-test.js only has newlines with no literal backslash-n, which is why it doesn't catch this. A row with both would.
- 主要言語
- C++
- スター
- 9.3k
- フォーク
- 845
- 平均マージ
- 1日 23時間
- マージ済み PR(30日)
- 558
環境構築
このプロジェクトの開発コンテナを、あなたの GitHub アカウントでブラウザ上に起動します。
- Dockerfile・Docker Compose ファイルなし
- プルリクエストのテンプレートなし
- コントリビューションガイドを読む
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
cloudflare/workerd のほかの issue
-
Build fails on macOS 27: dyld refuses stripped Rust proc-macros (mis-aligned LINKEDIT string pool)オープン
難易度 2/5 1〜3時間 初心者へのやさしさ 73/100
cloudflare/workerd#8963 ·
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
cloudflare/workerd#8807 ·
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
cloudflare/workerd#8575 ·
メンテナーはふだん 1 日以内に返信
-
fix(types): ForwardableEmailMessage omits the documented canBeForwarded property対応中かも @itsrayeedscodespace が 19 日前に担当しました。 オープン
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
cloudflare/workerd#8290 ·
メンテナーはふだん 1 日以内に返信
-
Streaming TextDecoder drops U+FEFF at the start of a chunk that follows an ASCII-only chunk再び着手できるかも @oliarmak-web が 19 日前に担当しましたが、オープン中のプルリクエストはありません。 オープン
難易度 2/5 1〜3時間 初心者へのやさしさ 82/100
cloudflare/workerd#8279 · コメント 1 件 ·
メンテナーはふだん 1 日以内に返信
cloudflare/workerd の issue をすべて見る
似ている issue
-
Android Bug Core Drape
難易度 2/5 1〜3時間 初心者へのやさしさ 77/100
organicmaps/organicmaps#14449 ·
メンテナーはふだん 1 日以内に返信
-
comp-codecs
難易度 2/5 1〜3時間 初心者へのやさしさ 84/100
ClickHouse/ClickHouse#135159 ·
メンテナーはふだん 1 日以内に返信
-
difficulty:easy func:python os:windows prio:high type:bug
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
NatronGitHub/Natron#2029 ·
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 67/100
ardazishvili/Sota#114 ·
メンテナーはふだん 1 日以内に返信
-
`Rect::containsPoint` is not `const`, so a `const Rect` cannot be asked whether it holds a pointオープンNeeds: Triage :mag:
難易度 1/5 1時間未満 初心者へのやさしさ 82/100
react/react-native#60349 ·
メンテナーはふだん 1 日以内に返信