D1 export: `quote()` in d1.js turns a literal `\n` into a newline when the value also has a real newline
Maintainer thường phản hồi trong vòng 1 ngày
Đánh giá
- Độ khó
- 2/5
- Thời gian dự kiến
- 1-3 giờ
- Mức phù hợp với người mới
- 85/100
- Loại issue
- Lỗi
- Độ rõ ràng
- Đặc tả rõ ràng
- Mức độ hoạt động
- Sôi nổi
- Công nghệ
- javascript
Hướng nghiên cứu
Đọc src/workerd/server/d1/d1.js và theo dõi quote() để xem cách chọn chuỗi escape cho ký tự xuống dòng và ký tự về đầu dòng. So sánh cách xử lý va chạm được mô tả cho shell.c.in và dumpSql.ts của Miniflare; sau đó kiểm tra d1-export-test.js. Thêm một trường hợp xuất chứa cả ký tự xuống dòng thật lẫn \n dạng literal (và trường hợp tương ứng với ký tự về đầu dòng), rồi xác nhận rằng bản xuất giữ nguyên cả hai giá trị khi được nhập.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
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.
- Ngôn ngữ chính
- C++
- Star
- 9.3k
- Fork
- 845
- Merge trung bình
- 1 ngày 23 giờ
- Pull request đã merge (30 ngày)
- 558
Chuẩn bị môi trường
Khởi chạy dev container của dự án ngay trên trình duyệt, bằng tài khoản GitHub của bạn.
- Không có Dockerfile hay tệp Docker Compose
- Không có mẫu pull request
- Đọc hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của cloudflare/workerd
-
Build fails on macOS 27: dyld refuses stripped Rust proc-macros (mis-aligned LINKEDIT string pool)Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 73/100
cloudflare/workerd#8963 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
cloudflare/workerd#8807 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
cloudflare/workerd#8575 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
fix(types): ForwardableEmailMessage omits the documented canBeForwarded propertyCó thể đã có người làm @itsrayeedscodespace đã nhận 19 ngày trước. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
cloudflare/workerd#8290 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Streaming TextDecoder drops U+FEFF at the start of a chunk that follows an ASCII-only chunkCó thể làm lại được @oliarmak-web đã nhận 19 ngày trước và không có pull request nào đang mở. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 82/100
cloudflare/workerd#8279 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
Tất cả issue của cloudflare/workerd
Issue tương tự
-
Android Bug Core Drape
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 77/100
organicmaps/organicmaps#14449 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
comp-codecs
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 84/100
ClickHouse/ClickHouse#135159 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
[raygui] update to 5.0Đang mởcategory:port-update
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 64/100
Maintainer thường phản hồi trong vòng 2 ngày
-
difficulty:easy func:python os:windows prio:high type:bug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
NatronGitHub/Natron#2029 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Broken mermaid sequence diagrams on "Invocation execution model" doc page (@ in actor names)Đang mởbug 🐞
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 74/100
Maintainer thường phản hồi trong vòng 2 ngày