mirror of https://github.com/tidwall/gjson.git
incomplete surrogate codepoints, fixes #38
This commit is contained in:
parent
4e8f0c7f28
commit
be96719f99
2
gjson.go
2
gjson.go
|
@ -1448,7 +1448,7 @@ func unescape(json string) string { //, error) {
|
||||||
i += 5
|
i += 5
|
||||||
if utf16.IsSurrogate(r) {
|
if utf16.IsSurrogate(r) {
|
||||||
// need another code
|
// need another code
|
||||||
if len(json) >= 6 && json[i] == '\\' && json[i+1] == 'u' {
|
if len(json[i:]) >= 6 && json[i] == '\\' && json[i+1] == 'u' {
|
||||||
// we expect it to be correct so just consume it
|
// we expect it to be correct so just consume it
|
||||||
r = utf16.DecodeRune(r, runeit(json[i+2:]))
|
r = utf16.DecodeRune(r, runeit(json[i+2:]))
|
||||||
i += 6
|
i += 6
|
||||||
|
|
|
@ -285,7 +285,17 @@ func TestPlus53BitInts(t *testing.T) {
|
||||||
// flip the number to the negative sign.
|
// flip the number to the negative sign.
|
||||||
assert(t, Get(json, "overflow_int64").Int() == -9223372036854775808)
|
assert(t, Get(json, "overflow_int64").Int() == -9223372036854775808)
|
||||||
}
|
}
|
||||||
|
func TestIssue38(t *testing.T) {
|
||||||
|
// These should not fail, even though the unicode is invalid.
|
||||||
|
Get(`["S3O PEDRO DO BUTI\udf93"]`, "0")
|
||||||
|
Get(`["S3O PEDRO DO BUTI\udf93asdf"]`, "0")
|
||||||
|
Get(`["S3O PEDRO DO BUTI\udf93\u"]`, "0")
|
||||||
|
Get(`["S3O PEDRO DO BUTI\udf93\u1"]`, "0")
|
||||||
|
Get(`["S3O PEDRO DO BUTI\udf93\u13"]`, "0")
|
||||||
|
Get(`["S3O PEDRO DO BUTI\udf93\u134"]`, "0")
|
||||||
|
Get(`["S3O PEDRO DO BUTI\udf93\u1345"]`, "0")
|
||||||
|
Get(`["S3O PEDRO DO BUTI\udf93\u1345asd"]`, "0")
|
||||||
|
}
|
||||||
func TestTypes(t *testing.T) {
|
func TestTypes(t *testing.T) {
|
||||||
assert(t, (Result{Type: String}).Type.String() == "String")
|
assert(t, (Result{Type: String}).Type.String() == "String")
|
||||||
assert(t, (Result{Type: Number}).Type.String() == "Number")
|
assert(t, (Result{Type: Number}).Type.String() == "Number")
|
||||||
|
|
Loading…
Reference in New Issue