RandomDocumentPicks#randomFieldName can produce invalid field name (#28419)

This change makes sure that this function does not create field names that end with a '.', more precisely it only allows
alpha-numeric characters to compose the leaf field name.

Closes #27373
This commit is contained in:
Jim Ferenczi 2018-01-31 09:21:09 +01:00 committed by GitHub
parent 202d28be86
commit 7edb978256
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 5 additions and 1 deletions

View File

@ -43,12 +43,16 @@ public final class RandomDocumentPicks {
public static String randomFieldName(Random random) {
int numLevels = RandomNumbers.randomIntBetween(random, 1, 5);
StringBuilder fieldName = new StringBuilder();
for (int i = 0; i < numLevels; i++) {
for (int i = 0; i < numLevels-1; i++) {
if (i > 0) {
fieldName.append('.');
}
fieldName.append(randomString(random));
}
if (numLevels > 1) {
fieldName.append('.');
}
fieldName.append(randomLeafFieldName(random));
return fieldName.toString();
}