Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow unicode escape sequences of emojis in quoted strings #128

Open
hpoul opened this issue Jun 22, 2022 · 2 comments
Open

Allow unicode escape sequences of emojis in quoted strings #128

hpoul opened this issue Jun 22, 2022 · 2 comments

Comments

@hpoul
Copy link

hpoul commented Jun 22, 2022

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"''');
void main(List<String> 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
Copy link

wosika commented Jan 11, 2023

have same problem . T T

@tamcy
Copy link
Contributor

tamcy commented Apr 8, 2024

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants
@hpoul @tamcy @wosika and others