Skip to content

Commit 6230390

Browse files
committed
Don't handle empty '[]' as character class
Fixes handling field names for JSON arrays like 'a[].1'
1 parent fdd7035 commit 6230390

File tree

2 files changed

+16
-6
lines changed

2 files changed

+16
-6
lines changed

metafacture-commons/src/main/java/org/metafacture/commons/tries/SimpleRegexTrie.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
public class SimpleRegexTrie<P> {
3030

3131
private final WildcardTrie<P> trie;
32-
public static final String SIMPLE_CHARACTER_CLASS = "\\[.*\\]";
32+
public static final String SIMPLE_CHARACTER_CLASS = "\\[.+\\]";
3333

3434
public SimpleRegexTrie() {
3535
trie = new WildcardTrie<P>();

metafacture-commons/src/test/java/org/metafacture/commons/tries/SimpleRegexTrieTest.java

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2013, 2014 Pascal Christoph, hbz
2+
* Copyright 2013, 2020 Pascal Christoph, hbz and others
33
* Licensed under the Apache License, Version 2.0 the "License";
44
* you may not use this file except in compliance with the License.
55
* You may obtain a copy of the License at
@@ -21,17 +21,27 @@
2121
/**
2222
* tests {@link SimpleRegexTrie}
2323
*
24-
* @author Pascal Christoph
24+
* @author Pascal Christoph, Fabian Steeg
2525
*
2626
*/
2727
public final class SimpleRegexTrieTest {
28-
private static final String SCC = "aacbb|a[ab]bb";
28+
2929
private static final String AACBB = "aacbb";
30+
private static final String ABCBB = "abcbb";
3031

3132
@Test
3233
public void testWithSimpleCharacterClass() {
3334
final SimpleRegexTrie<String> trie = new SimpleRegexTrie<String>();
34-
trie.put(SCC, SCC);
35-
assertTrue(AACBB, trie.get(AACBB).size() == 1);
35+
trie.put("a[ab]cbb", "value");
36+
assertTrue("Expecting to find: " + AACBB, trie.get(AACBB).size() == 1);
37+
assertTrue("Expecting to find: " + ABCBB, trie.get(ABCBB).size() == 1);
38+
}
39+
40+
@Test
41+
public void testWithEmptyCharacterClass() {
42+
final SimpleRegexTrie<String> trie = new SimpleRegexTrie<String>();
43+
// Should not be treated as character class (used for JSON arrays):
44+
trie.put("a[].1", "value");
45+
assertTrue("Expecting to find: a[].1", trie.get("a[].1").size() == 1);
3646
}
3747
}

0 commit comments

Comments
 (0)