Skip to content

Commit

Permalink
Fix: raise error on malformed CSV.
Browse files Browse the repository at this point in the history
Signed-off-by: dblock <[email protected]>
  • Loading branch information
dblock committed Nov 8, 2022
1 parent 88757b4 commit 578b7c3
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,9 @@ public KuromojiTokenizerFactory(IndexSettings indexSettings, Environment env, St

private static String parse(String rule, Set<String> dup) {
String[] values = CSVUtil.parse(rule);
if (values.length == 0) {
throw new IllegalArgumentException("Malformed csv in user dictionary.");
}
if (dup.add(values[0]) == false) {
throw new IllegalArgumentException("Found duplicate term [" + values[0] + "] in user dictionary.");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -379,6 +379,15 @@ public void testKuromojiAnalyzerInvalidUserDictOption() throws Exception {
);
}

public void testKuromojiAnalyzerEmptyDictRule() throws Exception {
Settings settings = Settings.builder()
.put("index.analysis.analyzer.my_analyzer.type", "kuromoji")
.putList("index.analysis.analyzer.my_analyzer.user_dictionary_rules", "\"")
.build();
RuntimeException exc = expectThrows(RuntimeException.class, () -> createTestAnalysis(settings));
assertThat(exc.getMessage(), equalTo("Line [1]: Malformed csv in user dictionary."));
}

public void testKuromojiAnalyzerDuplicateUserDictRule() throws Exception {
Settings settings = Settings.builder()
.put("index.analysis.analyzer.my_analyzer.type", "kuromoji")
Expand Down

0 comments on commit 578b7c3

Please sign in to comment.