dart-lang / yaml

A Dart YAML parser.
https://pub.dev/packages/yaml
MIT License
169 stars 58 forks source link

Allow unicode escape sequences of emojis in quoted strings #128

Open hpoul opened 2 years ago

hpoul commented 2 years ago

It should be allowed to add arbitrary escape sequences in quoted strings like:

example: "emoji \uD83D\uDE05"

the weird thing is that emojis in quoted strings work, but only if they are not escaped:

testYaml(r'''test: "Lorem ipsum 😅"''');
testYaml(r'''test: "Lorem ipsum \uD83D\uDE05"''');
```dart void main(List arguments) { testYaml(r'''test: "Lorem ipsum 😅"'''); testYaml(r'''test: "Lorem ipsum \uD83D\uDE05"'''); } void testYaml(String yamlSource) { try { final result = loadYaml(yamlSource); print('loaded: $result'); } catch (e) { print('error while loading: $e'); } } ```
loaded: {test: Lorem ipsum  😅}
error while loading: Error on line 1, column 22: Invalid Unicode character escape code.
  â•·
1 │ test: "Lorem ipsum   \uD83D\uDE05"
  │                      ^^^^^^
  ╵

I haven't found anything in the yaml spec which would limit the character set allowed as escaped characters.

wosika commented 1 year ago

have same problem . T T

tamcy commented 5 months ago

If you need to use characters like emoji which is encoded with two UTF-16 code units, you can just access it with the uppercase escape sequence \U and enter the UTF-32 codepoint directly.

For instance, 😅 is U+1F605, so you'd write:

test: "Lorem ipsum \U0001F605" # must be in 32 bits / 8 bytes.