D1 export: `quote()` in d1.js turns a literal `\n` into a newline when the value also has a real newline
Los mantenedores suelen responder en 1 día
Evaluación
- Dificultad
- 2/5
- Tiempo estimado
- 1-3 horas
- Aptitud para principiantes
- 85/100
- Tipo de issue
- Error
- Claridad
- Bien especificado
- Estado de actividad
- Activo
- Stack tecnológico
- javascript
Línea de trabajo
Lee src/workerd/server/d1/d1.js y sigue quote() para ver cómo se eligen las secuencias de escape de salto de línea y retorno de carro. Compara el tratamiento de colisiones descrito para shell.c.in y dumpSql.ts de Miniflare; después, inspecciona d1-export-test.js. Añade un caso de exportación que contenga tanto un salto de línea real como un \n literal (y el caso correspondiente de retorno de carro), y confirma que la exportación conserva ambos valores al importarlos.
Escrito por el modelo de indexación a partir del texto del issue.
Descripción
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.
- Lenguaje dominante
- C++
- Estrellas
- 9.3k
- Forks
- 845
- Merge medio
- 1 d 23 h
- PR fusionados (30 d)
- 558
Preparar el entorno
Inicia el contenedor de desarrollo del proyecto en tu navegador, con tu propia cuenta de GitHub.
- Sin Dockerfile ni archivo de Docker Compose
- Sin plantilla de pull request
- Leer la guía de contribución
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Más de cloudflare/workerd
-
Build fails on macOS 27: dyld refuses stripped Rust proc-macros (mis-aligned LINKEDIT string pool)Abierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 73/100
cloudflare/workerd#8963 ·
Los mantenedores suelen responder en 1 día
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 72/100
cloudflare/workerd#8807 ·
Los mantenedores suelen responder en 1 día
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 78/100
cloudflare/workerd#8575 ·
Los mantenedores suelen responder en 1 día
-
fix(types): ForwardableEmailMessage omits the documented canBeForwarded propertyPosiblemente ocupada @itsrayeedscodespace la tomó hace 18 días. Abierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 78/100
cloudflare/workerd#8290 ·
Los mantenedores suelen responder en 1 día
-
Streaming TextDecoder drops U+FEFF at the start of a chunk that follows an ASCII-only chunkQuizá libre de nuevo @oliarmak-web la tomó hace 19 días y no hay ningún pull request abierto. Abierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 82/100
cloudflare/workerd#8279 · 1 comentario ·
Los mantenedores suelen responder en 1 día
Todos los issues de cloudflare/workerd
Issues similares
-
Android Bug Core Drape
Dificultad 2/5 1-3 horas Aptitud para principiantes 77/100
organicmaps/organicmaps#14449 ·
Los mantenedores suelen responder en 1 día
-
comp-codecs
Dificultad 2/5 1-3 horas Aptitud para principiantes 84/100
ClickHouse/ClickHouse#135159 ·
Los mantenedores suelen responder en 1 día
-
difficulty:easy func:python os:windows prio:high type:bug
Dificultad 2/5 1-3 horas Aptitud para principiantes 78/100
NatronGitHub/Natron#2029 ·
Los mantenedores suelen responder en 1 día
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 67/100
ardazishvili/Sota#114 ·
Los mantenedores suelen responder en 1 día
-
`Rect::containsPoint` is not `const`, so a `const Rect` cannot be asked whether it holds a pointAbiertoNeeds: Triage :mag:
Dificultad 1/5 Menos de una hora Aptitud para principiantes 82/100
react/react-native#60349 ·
Los mantenedores suelen responder en 1 día