-
-
Notifications
You must be signed in to change notification settings - Fork 749
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Handle UTF8 Surrogate Pairs in Parser (#6503)
- Loading branch information
1 parent
58c9ef1
commit 19406aa
Showing
2 changed files
with
74 additions
and
60 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
19 changes: 19 additions & 0 deletions
19
src/HotChocolate/Language/test/Language.Tests/Parser/ParseUtf8SurrogatePairTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
using System.Text; | ||
using Newtonsoft.Json; | ||
using Xunit; | ||
|
||
namespace HotChocolate.Language; | ||
|
||
public class ParseUtf8SurrogatePairTests | ||
{ | ||
[Fact] | ||
public void Handle_UTF8_Surrogate_Pairs_Correctly() | ||
{ | ||
var emojiBytes = System.Text.Json.JsonSerializer.SerializeToUtf8Bytes("😀"); | ||
var reader = new Utf8GraphQLReader(emojiBytes); | ||
Assert.Equal("😀", System.Text.Json.JsonSerializer.Deserialize<string>(emojiBytes)); | ||
Assert.Equal("😀", JsonConvert.DeserializeObject<string>(Encoding.UTF8.GetString(emojiBytes))); | ||
Assert.True(reader.Read()); | ||
Assert.Equal("😀", reader.GetString()); | ||
} | ||
} |