|
1 |
| -package com.fasterxml.jackson.core.json; |
| 1 | +package com.fasterxml.jackson.core.write; |
2 | 2 |
|
3 | 3 | import java.io.ByteArrayOutputStream;
|
4 | 4 | import java.io.StringWriter;
|
5 | 5 | import java.io.Writer;
|
6 | 6 |
|
7 | 7 | import com.fasterxml.jackson.core.*;
|
| 8 | +import com.fasterxml.jackson.core.json.JsonWriteFeature; |
8 | 9 |
|
9 | 10 | import org.junit.jupiter.api.Test;
|
10 | 11 |
|
11 | 12 | import static org.junit.jupiter.api.Assertions.assertEquals;
|
12 | 13 | import static org.junit.jupiter.api.Assertions.assertFalse;
|
| 14 | +import static org.junit.jupiter.api.Assertions.assertTrue; |
13 | 15 |
|
14 |
| -class Surrogate223Test extends JUnit5TestBase |
| 16 | +class SurrogateWrite223Test extends JUnit5TestBase |
15 | 17 | {
|
16 | 18 | private final JsonFactory DEFAULT_JSON_F = newStreamFactory();
|
17 | 19 |
|
@@ -90,4 +92,35 @@ void surrogatesCharBacked() throws Exception
|
90 | 92 | assertToken(JsonToken.END_ARRAY, p.nextToken());
|
91 | 93 | p.close();
|
92 | 94 | }
|
| 95 | + |
| 96 | + //https://github.com/FasterXML/jackson-core/issues/1359 |
| 97 | + @Test |
| 98 | + void checkNonSurrogates() throws Exception { |
| 99 | + JsonFactory f = JsonFactory.builder() |
| 100 | + .enable(JsonWriteFeature.COMBINE_UNICODE_SURROGATES_IN_UTF8) |
| 101 | + .build(); |
| 102 | + ByteArrayOutputStream out = new ByteArrayOutputStream(); |
| 103 | + try (JsonGenerator gen = f.createGenerator(out)) { |
| 104 | + gen.writeStartObject(); |
| 105 | + |
| 106 | + // Inside the BMP, beyond surrogate block; 0xFF0C - full-width comma |
| 107 | + gen.writeStringField("test_full_width", "foo" + new String(Character.toChars(0xFF0C)) + "bar"); |
| 108 | + |
| 109 | + // Inside the BMP, beyond surrogate block; 0xFE6A - small form percent |
| 110 | + gen.writeStringField("test_small_form", "foo" + new String(Character.toChars(0xFE6A)) + "bar"); |
| 111 | + |
| 112 | + // Inside the BMP, before the surrogate block; 0x3042 - Hiragana A |
| 113 | + gen.writeStringField("test_hiragana", "foo" + new String(Character.toChars(0x3042)) + "bar"); |
| 114 | + |
| 115 | + // Outside the BMP; 0x1F60A - emoji |
| 116 | + gen.writeStringField("test_emoji", new String(Character.toChars(0x1F60A))); |
| 117 | + |
| 118 | + gen.writeEndObject(); |
| 119 | + } |
| 120 | + String json = out.toString("UTF-8"); |
| 121 | + assertTrue(json.contains("foo\uFF0Cbar")); |
| 122 | + assertTrue(json.contains("foo\uFE6Abar")); |
| 123 | + assertTrue(json.contains("foo\u3042bar")); |
| 124 | + assertTrue(json.contains("\"test_emoji\":\"\uD83D\uDE0A\"")); |
| 125 | + } |
93 | 126 | }
|
0 commit comments