Skip to content

Commit 2ff43ca

Browse files
committed
update test
1 parent 70981b0 commit 2ff43ca

File tree

2 files changed

+29
-1
lines changed

2 files changed

+29
-1
lines changed

server/src/main/java/org/elasticsearch/features/InfrastructureFeatures.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff 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

x-pack/plugin/logsdb/qa/rolling-upgrade/src/javaRestTest/java/org/elasticsearch/xpack/logsdb/FlattenedRollingUpgradeIT.java

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
import org.elasticsearch.datageneration.datasource.DefaultObjectGenerationHandler;
2525
import org.elasticsearch.datageneration.matchers.MatchResult;
2626
import org.elasticsearch.datageneration.matchers.Matcher;
27+
import org.elasticsearch.features.InfrastructureFeatures;
2728
import org.elasticsearch.index.IndexSettings;
2829
import org.elasticsearch.test.ESTestCase;
2930
import 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
}

0 commit comments

Comments
 (0)