Skip to content

jsony doesn't handle UTF-16 surrogate pairs #45

Closed
@ghost

Description

As of now, jsony doesn't recognize surrogate pairs and just keeps them as-is, resulting in invalid UTF-8 characters:

import std/json
import pkg/jsony

type
  TestObj = object
    content: string

let
  # A string with 🔒 emoji encoded both as normal UTF-8 and as a surrogate pair
  raw = """{"content":"\uD83D\uDD12🔒"}"""
  parsed = raw.fromJson(TestObj)
  parsedStd = parseJson(raw).to(TestObj)

echo "jsony - ", parsed.content
echo "std/json - ", parsedStd.content

Both std/json and nim-json-serialization handle surrogates, so I think jsony should also support them.

Found out about this bug from a discussion with @zedeus.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions