Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,9 @@ private static MapperParsingException wrapInMapperParsingException(SourceToParse
private static String[] splitAndValidatePath(String fullFieldPath) {
if (fullFieldPath.contains(".")) {
String[] parts = fullFieldPath.split("\\.");
if (parts.length == 0) {
throw new IllegalArgumentException("field name cannot contain only dots");
}
for (String part : parts) {
if (Strings.hasText(part) == false) {
// check if the field name contains only whitespace
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1656,6 +1656,16 @@ public void testBlankFieldNames() throws Exception {
assertThat(err.getCause().getMessage(), containsString("field name cannot be an empty string"));
}

public void testDotsOnlyFieldNames() throws Exception {
DocumentMapper mapper = createDocumentMapper(mapping(b -> {}));
MapperParsingException err = expectThrows(
MapperParsingException.class,
() -> mapper.parse(source(b -> b.field(randomFrom(".", "..", "..."), "bar")))
);
assertThat(err.getCause(), notNullValue());
assertThat(err.getCause().getMessage(), containsString("field name cannot contain only dots"));
}

public void testWriteToFieldAlias() throws Exception {
DocumentMapper mapper = createDocumentMapper(mapping(b -> {
b.startObject("alias-field");
Expand Down