File tree Expand file tree Collapse file tree 2 files changed +29
-1
lines changed
server/src/main/java/org/elasticsearch/features
x-pack/plugin/logsdb/qa/rolling-upgrade/src/javaRestTest/java/org/elasticsearch/xpack/logsdb Expand file tree Collapse file tree 2 files changed +29
-1
lines changed Original file line number Diff line number Diff line change @@ -43,9 +43,14 @@ public class InfrastructureFeatures implements FeatureSpecification {
4343 public static final NodeFeature CURRENT_VERSION = new NodeFeature ("ES_" + RestApiVersion .current ());
4444 private static final NodeFeature PREVIOUS_VERSION = new NodeFeature ("ES_" + RestApiVersion .previous (), true );
4545
46+ public static final NodeFeature JACKSON_COMBINE_UNICODE_SURROGATES_IN_UTF8 = new NodeFeature (
47+ "jackson_combine_unicode_surrogates_in_utf8" ,
48+ true
49+ );
50+
4651 @ Override
4752 public Set <NodeFeature > getFeatures () {
48- return Set .of (CURRENT_VERSION , PREVIOUS_VERSION );
53+ return Set .of (CURRENT_VERSION , PREVIOUS_VERSION , JACKSON_COMBINE_UNICODE_SURROGATES_IN_UTF8 );
4954 }
5055
5156 @ Override
Original file line number Diff line number Diff line change 2424import org .elasticsearch .datageneration .datasource .DefaultObjectGenerationHandler ;
2525import org .elasticsearch .datageneration .matchers .MatchResult ;
2626import org .elasticsearch .datageneration .matchers .Matcher ;
27+ import org .elasticsearch .features .InfrastructureFeatures ;
2728import org .elasticsearch .index .IndexSettings ;
2829import org .elasticsearch .test .ESTestCase ;
2930import org .elasticsearch .test .rest .ObjectPath ;
@@ -86,6 +87,12 @@ public String generateFieldName() {
8687 if (candidate .contains ("\0 " )) {
8788 continue ;
8889 }
90+ if (oldClusterHasFeature (InfrastructureFeatures .JACKSON_COMBINE_UNICODE_SURROGATES_IN_UTF8 ) == false ) {
91+ candidate = stripUnpairedSurrogates (candidate );
92+ if (candidate .isBlank ()) {
93+ continue ;
94+ }
95+ }
8996 return candidate ;
9097 }
9198 }
@@ -270,4 +277,20 @@ public void testIndexing() throws IOException {
270277 }
271278 }
272279
280+ private static String stripUnpairedSurrogates (String s ) {
281+ StringBuilder sb = new StringBuilder (s .length ());
282+ for (int i = 0 ; i < s .length (); i ++) {
283+ char c = s .charAt (i );
284+ if (Character .isHighSurrogate (c )) {
285+ if (i + 1 < s .length () && Character .isLowSurrogate (s .charAt (i + 1 ))) {
286+ sb .append (c );
287+ sb .append (s .charAt (++i ));
288+ }
289+ } else if (Character .isLowSurrogate (c ) == false ) {
290+ sb .append (c );
291+ }
292+ }
293+ return sb .toString ();
294+ }
295+
273296}
You can’t perform that action at this time.
0 commit comments