Skip to content

Commit 8d9874a

Browse files
committed
fix
1 parent 6f33208 commit 8d9874a

File tree

3 files changed

+11
-2
lines changed

3 files changed

+11
-2
lines changed

core/src/main/java/com/taobao/arthas/core/util/RegexCacheManager.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ public static RegexCacheManager getInstance() {
2929
* 获取正则表达式Pattern对象,优先从缓存获取,缓存未命中则编译并缓存
3030
*/
3131
public Pattern getPattern(String regex) {
32-
if (regex == null || regex.isEmpty()) {
32+
if (regex == null) {
3333
return null;
3434
}
3535

core/src/test/java/com/taobao/arthas/core/util/RegexCacheManagerTest.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,10 @@ public void testBasicCacheFunctionality() {
4949
Assert.assertNull(nullPattern);
5050

5151
Pattern emptyPattern = cacheManager.getPattern("");
52-
Assert.assertNull(emptyPattern);
52+
Assert.assertNotNull(emptyPattern);
53+
Assert.assertTrue(emptyPattern.matcher("").matches());
54+
Assert.assertFalse(emptyPattern.matcher("non-empty").matches());
55+
Assert.assertEquals(3, cacheManager.getCacheSize());
5356
}
5457

5558
/**

core/src/test/java/com/taobao/arthas/core/util/matcher/RegexMatcherTest.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,12 @@ public void testMatchingWithNullInputs(){
1616
Assert.assertTrue(new RegexMatcher("foobar").matching("foobar"));
1717
}
1818

19+
@Test
20+
public void testMatchingWithEmptyPattern() {
21+
Assert.assertTrue(new RegexMatcher("").matching(""));
22+
Assert.assertFalse(new RegexMatcher("").matching("foobar"));
23+
}
24+
1925
/**
2026
* test regux with . | * + ? \s \S \w \W and so on...
2127
*/

0 commit comments

Comments
 (0)