Skip to content

Commit

Permalink
Minor tweaking
Browse files Browse the repository at this point in the history
  • Loading branch information
cowtowncoder committed Nov 15, 2024
1 parent 727d8ef commit ec49914
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 7 deletions.
5 changes: 5 additions & 0 deletions release-notes/CREDITS-2.x
Original file line number Diff line number Diff line change
Expand Up @@ -456,3 +456,8 @@ Jared Stehler (@jaredstehler)
Zhanghao (@zhangOranges)
* Contributed #1305: Make helper methods of `WriterBasedJsonGenerator` non-final to allow overriding
(2.18.0)

Justin Gosselin (@jgosselin-accesso)
* Reported #1359: Non-surrogate characters being incorrectly combined when
`JsonWriteFeature.COMBINE_UNICODE_SURROGATES_IN_UTF8` is enabled
(2.18.2)
4 changes: 4 additions & 0 deletions release-notes/VERSION-2.x
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ a pure JSON library.

#1353: Use fastdoubleparser 1.0.90
(fixed by @pjfanning)
#1359: Non-surrogate characters being incorrectly combined when
`JsonWriteFeature.COMBINE_UNICODE_SURROGATES_IN_UTF8` is enabled
(reported by Justin G)
(fixed by @pjfanning)

2.18.0 (26-Sep-2024)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2248,7 +2248,8 @@ private byte[] getHexBytes() {

// @since 2.18
private static boolean _isStartOfSurrogatePair(final int ch) {
return (ch & 0xF800) == 0xD800;
// In 0xD800 - 0xDBFF range?
return (ch & 0xFC00) == 0xD800;
}
}

Original file line number Diff line number Diff line change
@@ -1,18 +1,19 @@
package com.fasterxml.jackson.core.json;
package com.fasterxml.jackson.core.write;

import java.io.ByteArrayOutputStream;
import java.io.StringWriter;
import java.io.Writer;

import com.fasterxml.jackson.core.*;
import com.fasterxml.jackson.core.json.JsonWriteFeature;

import org.junit.jupiter.api.Test;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;

class Surrogate223Test extends JUnit5TestBase
class SurrogateWrite223Test extends JUnit5TestBase
{
private final JsonFactory DEFAULT_JSON_F = newStreamFactory();

Expand Down Expand Up @@ -92,14 +93,15 @@ void surrogatesCharBacked() throws Exception
p.close();
}

//https://github.com/FasterXML/jackson-core/issues/1359
@Test
void checkNonSurrogates() throws Exception {
//https://github.com/FasterXML/jackson-core/issues/1359
JsonFactory factory = new JsonFactory();
JsonFactory f = JsonFactory.builder()
.enable(JsonWriteFeature.COMBINE_UNICODE_SURROGATES_IN_UTF8)
.build();
ByteArrayOutputStream out = new ByteArrayOutputStream();
try (JsonGenerator gen = factory.createGenerator(out)) {
try (JsonGenerator gen = f.createGenerator(out)) {
gen.writeStartObject();
gen.enable(JsonGenerator.Feature.COMBINE_UNICODE_SURROGATES_IN_UTF8);

// Inside the BMP, beyond surrogate block; 0xFF0C - full-width comma
gen.writeStringField("test_full_width", "foo" + new String(Character.toChars(0xFF0C)) + "bar");
Expand Down

0 comments on commit ec49914

Please sign in to comment.