Skip to content

Commit 49950e4

Browse files
kyleconroyclaude
andauthored
endtoend: pin sqlite query text with multi-byte UTF-8 comments (#4568)
The ANTLR-based sqlite parser mixed rune-counted and byte-counted offsets when slicing query text out of the source file, so a multi-byte character in a comment silently truncated the generated query string and leaked fragments of neighboring statements into it. The meyer parser tracks byte offsets throughout, which fixed this; this case keeps it fixed. Covers the three reported shapes: an em dash in a comment directly above the annotation, a standalone comment between two queries, and CJK comments. Fixes #4523 Fixes #4235 Fixes #4372 Claude-Session: https://claude.ai/code/session_017bkCyEYanANjRyamjUF8ZP Co-authored-by: Claude <noreply@anthropic.com>
1 parent e76cf63 commit 49950e4

6 files changed

Lines changed: 164 additions & 0 deletions

File tree

internal/endtoend/testdata/multibyte_comment/sqlite/go/db.go

Lines changed: 31 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

internal/endtoend/testdata/multibyte_comment/sqlite/go/models.go

Lines changed: 11 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

internal/endtoend/testdata/multibyte_comment/sqlite/go/query.sql.go

Lines changed: 85 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
-- Multi-byte UTF-8 in comments must not shift the byte offsets used to slice
2+
-- query text out of the source file (#4523, #4235, #4372).
3+
4+
-- name: ListItems :many
5+
-- an em dash right here — must not truncate the ORDER BY below
6+
SELECT id, name, cap_read
7+
FROM items WHERE cap_read = 'anonymous' ORDER BY name;
8+
9+
-- section — divider between queries
10+
11+
-- name: UpdateItem :exec
12+
UPDATE items SET name = ? WHERE id = ?;
13+
14+
-- name: CreateItem :exec
15+
-- 当新建条目时,需要写入名称和权限
16+
INSERT INTO items (name, cap_read)
17+
VALUES (?, ?);
18+
19+
-- name: DeleteItem :one
20+
DELETE FROM items WHERE id = ? RETURNING id, name, cap_read;
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
CREATE TABLE items (
2+
id INTEGER PRIMARY KEY,
3+
name TEXT NOT NULL,
4+
cap_read TEXT NOT NULL
5+
);
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{
2+
"version": "1",
3+
"packages": [
4+
{
5+
"path": "go",
6+
"engine": "sqlite",
7+
"name": "querytest",
8+
"schema": "schema.sql",
9+
"queries": "query.sql"
10+
}
11+
]
12+
}

0 commit comments

Comments
 (0)