jpsim / Yams

A Sweet and Swifty YAML parser.
https://jpsim.com/Yams
MIT License
1.12k stars 144 forks source link

Emojis get escaped when serializing #400

Open ahartwel opened 1 year ago

ahartwel commented 1 year ago

If a yaml string has emojis inside of it, after running serialize they are escaped in the final output.

For example

this:

test:
  a_key: "hello 🥹"
  another:
    test: "test"
    test2: "test2"

gets turned into

test:
  a_key: "hello \U0001F979"
  another:
    test: "test"
    test2: "test2"

after going through a Yams.compose -> Yams.serialize cycle.

Here's a simple repro:

let yaml = """
test:
  a_key: "hello 🥹"
  another:
    test: "test"
    test2: "test2"
"""

let node = try Yams.compose(yaml: yaml)
let newString = try Yams.serialize(node: node!, allowUnicode: true)
print(newString)
samuelhe52 commented 4 months ago

I encountered the exact same issue here. I'm using Yams.dump() to dump a dictionary:

import Foundation
import Yams

let testDict = ["testkey": "🔰test value with emoji"]

let desktopFolder = FileManager.default.urls(for: .desktopDirectory, in: .userDomainMask).first!

let ymlData = try Yams.dump(object: testDict).data(using: .utf8)!

try ymlData.write(to: desktopFolder.appending(path: "test.yaml"))

The result:

testkey: "\U0001F530test value with emoji"

Has anyone found a solution to this problem?