Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/main/java/com/google/code/regexp/Matcher.java
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,7 @@ public List<Map<String, String>> namedGroups() {
}

int nextIndex = 0;
while (matcher.find(nextIndex)) {
while (!matcher.hitEnd() && matcher.find(nextIndex)) {
Map<String, String> matches = new LinkedHashMap<String, String>();

for (String groupName : groupNames) {
Expand Down
9 changes: 9 additions & 0 deletions src/test/java/com/google/code/regexp/MatcherTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -754,4 +754,13 @@ public void testNamedGroupsReturnsEmptyListWhenNoGroupPresent() {
final List<Map<String, String>> groups = matcher.namedGroups();
assertTrue(groups.isEmpty());
}

// Specify 1 second timeout to account for potential infinite loop (Issue #16)
@Test(timeout=1000)
public void testNamedGroupsReturnsWhenMatchesEmptyString() {
com.google.code.regexp.Matcher matcher = com.google.code.regexp.Pattern.compile("(?<foo>.*)").matcher("bar");
final List<Map<String, String>> groups = matcher.namedGroups();
assertEquals(1, groups.size());
assertEquals("bar", groups.get(0).get("foo"));
}
}