Skip to content

Commit

Permalink
Don't validate dynamic portions in an index for lowercase
Browse files Browse the repository at this point in the history
  • Loading branch information
costin committed Jun 22, 2015
1 parent a6eea45 commit 6254525
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 1 deletion.
18 changes: 17 additions & 1 deletion mr/src/main/java/org/elasticsearch/hadoop/rest/Resource.java
Expand Up @@ -74,7 +74,23 @@ public Resource(Settings settings, boolean read) {

Assert.hasText(index, "No index found; expecting [index]/[type]");
Assert.hasText(type, "No type found; expecting [index]/[type]");
Assert.isTrue(StringUtils.isLowerCase(index), String.format("Invalid index [%s] - needs to be lowercase", index));

StringBuilder fixedIndex = new StringBuilder();
if (index.contains("{") && index.contains("}")) {
int startPattern = index.indexOf("{");
int endPattern = index.indexOf("}");
if (endPattern > startPattern) {
fixedIndex.append(index.substring(0, startPattern));
fixedIndex.append(index.substring(endPattern + 1, index.length()));
}
else {
fixedIndex.append(index);
}
}
else {
fixedIndex.append(index);
}
Assert.isTrue(StringUtils.isLowerCase(fixedIndex), String.format("Invalid index [%s] - needs to be lowercase", index));

indexAndType = index + "/" + type;

Expand Down
21 changes: 21 additions & 0 deletions mr/src/test/java/org/elasticsearch/hadoop/rest/ResourceTest.java
Expand Up @@ -65,6 +65,27 @@ public void testQueryUriWithParams() throws Exception {
assertEquals("foo/bar", res.indexAndType());
}

@Test
public void testDynamicFieldLowercase() throws Exception {
Resource res = createResource("foo/Fbar");
res = createResource("foo-{F}/bar");
}

@Test(expected = EsHadoopIllegalArgumentException.class)
public void testLowercaseNotAllowed() throws Exception {
createResource("fooF/bar");
}

@Test(expected = EsHadoopIllegalArgumentException.class)
public void testLowercaseNotAllowedIfTemplateIsInvalid() throws Exception {
createResource("foo{F/bar");
}

@Test(expected = EsHadoopIllegalArgumentException.class)
public void testLowercaseNotAllowedIfTemplateIsInvalidAgain() throws Exception {
createResource("foo}F{/bar");
}

private Resource createResource(String target) {
Settings s = new TestSettings();
s.setProperty(ConfigurationOptions.ES_RESOURCE, target);
Expand Down

0 comments on commit 6254525

Please sign in to comment.