Skip to content

Commit 9d775c7

Browse files
committed
Fix UrlTokenFilter issue when no tokens are returned by UrlTokenizer
1 parent 8d983c0 commit 9d775c7

File tree

3 files changed

+12
-1
lines changed

3 files changed

+12
-1
lines changed

src/main/java/org/elasticsearch/index/analysis/url/URLTokenFilter.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,9 @@ private boolean advance() throws IOException {
130130
}
131131
throw e;
132132
}
133+
if (tokens.isEmpty()) {
134+
return false;
135+
}
133136
iterator = tokens.iterator();
134137
return true;
135138
} else {

src/test/java/org/elasticsearch/index/analysis/url/URLTokenFilterTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ public void testFilterPort() throws IOException {
3737
@Test
3838
public void testFilterPath() throws IOException {
3939
assertTokenStreamContents(createFilter(TEST_HTTP_URL, URLPart.PATH).setTokenizePath(false), "/index_name/type_name/_search.html");
40-
assertTokenStreamContents(createFilter(TEST_HTTP_URL2, URLPart.PATH).setTokenizePath(false), "");
40+
assertTokenStreamContents(createFilter(TEST_HTTP_URL2, URLPart.PATH).setTokenizePath(false), new String[]{});
4141
}
4242

4343
@Test

src/test/java/org/elasticsearch/index/analysis/url/URLTokenizerTest.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,14 @@ public void testTokenizePath() throws IOException {
8383
}
8484

8585

86+
@Test
87+
public void testTokenizeNoPath() throws Exception {
88+
final String url = "http://www.foo.bar.com:9200";
89+
URLTokenizer tokenizer = createTokenizer(url, URLPart.PATH);
90+
assertTokenStreamContents(tokenizer, stringArray());
91+
}
92+
93+
8694
@Test
8795
public void testTokenizeQuery() throws IOException {
8896
URLTokenizer tokenizer = createTokenizer(TEST_HTTP_URL, URLPart.QUERY);

0 commit comments

Comments
 (0)