Make sure mysql select json object keys are escaped.
This commit is contained in:
parent
1c2a595750
commit
a1d7684fc1
4 changed files with 96 additions and 1 deletions
|
|
@ -914,3 +914,45 @@ func TestSelectJson_InvalidJson(t *testing.T) {
|
|||
err := stmt.QueryContext(ctx, db, &dest)
|
||||
require.ErrorContains(t, err, "invalid json")
|
||||
}
|
||||
|
||||
func TestSelectJsonObject_EscapesJsonKeys(t *testing.T) {
|
||||
stmt := SELECT_JSON_OBJ(
|
||||
String("value").AS("author"),
|
||||
String("value").AS("author's name"),
|
||||
String("value").AS("author''s name"),
|
||||
String("value").AS(`C:\tmp\file`),
|
||||
String("value").AS("hello\nworld"),
|
||||
String("value").AS("a'b\\\\c\\nd\\r\\x00e\\x1af"),
|
||||
String("value").AS("žika 😀"),
|
||||
)
|
||||
|
||||
testutils.AssertDebugStatementSql(t, stmt, `
|
||||
SELECT row_to_json(records) AS "json"
|
||||
FROM (
|
||||
SELECT 'value'::text AS "author",
|
||||
'value'::text AS "author's name",
|
||||
'value'::text AS "author''s name",
|
||||
'value'::text AS "C:\tmp\file",
|
||||
'value'::text AS "hello
|
||||
world",
|
||||
'value'::text AS "a'b\\c\nd\r\x00e\x1af",
|
||||
'value'::text AS "žika 😀"
|
||||
) AS records;
|
||||
`)
|
||||
|
||||
var dest map[string]any
|
||||
|
||||
err := stmt.QueryContext(ctx, db, &dest)
|
||||
require.NoError(t, err)
|
||||
testutils.AssertJSON(t, dest, `
|
||||
{
|
||||
"C:\\tmp\\file": "value",
|
||||
"a'b\\\\c\\nd\\r\\x00e\\x1af": "value",
|
||||
"author": "value",
|
||||
"author''s name": "value",
|
||||
"author's name": "value",
|
||||
"hello\nworld": "value",
|
||||
"žika 😀": "value"
|
||||
}
|
||||
`)
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue