Skip to content
Open
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 java/com/google/re2j/Pattern.java
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,7 @@ private String[] split(Matcher m, int limit) {
result.add(m.substring(last, m.inputLength()));
}

if (limit != 0 || result.isEmpty()) {
if (limit != 0 || (result.isEmpty() && !(last == m.inputLength() && last > 0))) {
result.add(m.substring(last, m.inputLength()));
}

Expand Down
7 changes: 7 additions & 0 deletions javatests/com/google/re2j/PatternTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,13 @@ public void testSplit() {
ApiTestUtils.testSplit("x*", "foo", 1, new String[] {"foo"});
ApiTestUtils.testSplit("x*", "f", 2, new String[] {"f", ""});
ApiTestUtils.testSplit(":", ":a::b", new String[] {"", "a", "", "b"});

// From https://github.com/google/re2j/issues/197.
// Test split when input is fully matched and limit is 0.
ApiTestUtils.testSplit("\\s+", " ", new String[] {});
ApiTestUtils.testSplit("\\s+", " foo", new String[] {"", "foo"});
ApiTestUtils.testSplit("\\s+", "foo ", new String[] {"foo"});
ApiTestUtils.testSplit("\\s+", "", new String[] {""});
}

@Test
Expand Down
Loading