From 97db48cb1dc49953c1f725a10ae01ed427059c82 Mon Sep 17 00:00:00 2001 From: Matt Robenolt Date: Mon, 29 Apr 2024 08:59:04 -0700 Subject: [PATCH] cast: JSON is always UTF8 --- __tests__/golden.test.ts | 2 +- golden/database.json | 4 ++-- golden/test.sql | 2 +- src/cast.ts | 2 +- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/__tests__/golden.test.ts b/__tests__/golden.test.ts index 4c064f8..8277fe9 100644 --- a/__tests__/golden.test.ts +++ b/__tests__/golden.test.ts @@ -62,7 +62,7 @@ describe('golden', () => { aa: 'aa', ab: 'foo', ac: 'foo,bar', - ad: { ad: null }, + ad: { ad: null, foo: 'ü' }, ae: uint8ArrayFromHex( '0x0000000001020000000300000000000000000000000000000000000000000000000000F03F000000000000F03F00000000000000400000000000000000' ), diff --git a/golden/database.json b/golden/database.json index c26f3a8..9c5b616 100644 --- a/golden/database.json +++ b/golden/database.json @@ -514,7 +514,7 @@ "2", "3", "7", - "12", + "25", "61", "25", "61", @@ -529,7 +529,7 @@ "2", "-1" ], - "values": "MTExMTExMS4xMS4xMS4xMS4xBzEwMDAtMDEtMDExMDAwLTAxLTAxIDAxOjAxOjAxMTk3MC0wMS0wMSAwMDowMTowMTAxOjAxOjAxMjAwNnBxcgAAAHN0dXZ3eHl6YWFmb29mb28sYmFyeyJhZCI6IG51bGx9AAAAAAECAAAAAwAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAADwPwAAAAAAAPA/AAAAAAAAAEAAAAAAAAAAAAAAAAABAQAAAAAAAAAAAPA/AAAAAAAA8D8AAAAAAQIAAAADAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAPA/AAAAAAAA8D8AAAAAAAAAQAAAAAAAAAAAAAAAAAEDAAAAAgAAAAQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAIQAAAAAAAAAhAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAABAAAAAAAAAAAAPA/AAAAAAAA8D8AAAAAAADwPwAAAAAAAABAAAAAAAAAAEAAAAAAAADwPwAAAAAAAPA/AAAAAAAA8D8xMTExeGF4YnhjAAB4ZA==" + "values": "MTExMTExMS4xMS4xMS4xMS4xBzEwMDAtMDEtMDExMDAwLTAxLTAxIDAxOjAxOjAxMTk3MC0wMS0wMSAwMDowMTowMTAxOjAxOjAxMjAwNnBxcgAAAHN0dXZ3eHl6YWFmb29mb28sYmFyeyJhZCI6IG51bGwsICJmb28iOiAiw7wifQAAAAABAgAAAAMAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA8D8AAAAAAADwPwAAAAAAAABAAAAAAAAAAAAAAAAAAQEAAAAAAAAAAADwPwAAAAAAAPA/AAAAAAECAAAAAwAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAADwPwAAAAAAAPA/AAAAAAAAAEAAAAAAAAAAAAAAAAABAwAAAAIAAAAEAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAACEAAAAAAAAAIQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAQAAAAAAAAAAADwPwAAAAAAAPA/AAAAAAAA8D8AAAAAAAAAQAAAAAAAAABAAAAAAAAA8D8AAAAAAADwPwAAAAAAAPA/MTExMXhheGJ4YwAAeGQ=" } ] } diff --git a/golden/test.sql b/golden/test.sql index 98046b8..b6eddcc 100644 --- a/golden/test.sql +++ b/golden/test.sql @@ -79,7 +79,7 @@ INSERT INTO `test` VALUES ( 'aa', 'foo', 'foo,bar', - '{"ad":null}', + '{"ad":null,"foo":"ü"}', ST_GeomFromText('LINESTRING(0 0, 1 1, 2 0)'), POINT(1, 1), ST_GeomFromText('LINESTRING(0 0, 1 1, 2 0)'), diff --git a/src/cast.ts b/src/cast.ts index fea0bac..f13c6b8 100644 --- a/src/cast.ts +++ b/src/cast.ts @@ -23,7 +23,7 @@ export function cast(field: Field, value: any): any { } if (isJson(field)) { - return JSON.parse(value) + return JSON.parse(decodeUtf8(value)) } if (isIntegral(field)) {