Skip to content

Commit d6d43ef

Browse files
committed
Merge pull request #39 from abersnaze/long-pattern
Fixed a bug where long patterns across chunks were not found.
2 parents 0a5fb5d + c262c44 commit d6d43ef

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed

src/main/java/rx/observables/StringObservable.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -423,10 +423,10 @@ public void onError(Throwable e) {
423423

424424
@Override
425425
public void onNext(String segment) {
426+
if (leftOver != null)
427+
segment = leftOver + segment;
426428
String[] parts = pattern.split(segment, -1);
427429

428-
if (leftOver != null)
429-
parts[0] = leftOver + parts[0];
430430
for (int i = 0; i < parts.length - 1; i++) {
431431
String part = parts[i];
432432
output(part);

src/test/java/rx/observables/StringObservableTest.java

+12
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717

1818
import static org.junit.Assert.assertArrayEquals;
1919
import static org.junit.Assert.assertEquals;
20+
import static org.junit.Assert.assertFalse;
2021
import static org.junit.Assert.assertNotSame;
2122
import static org.junit.Assert.assertTrue;
2223
import static org.junit.Assert.fail;
@@ -46,6 +47,7 @@
4647
import java.nio.charset.CharsetDecoder;
4748
import java.nio.charset.MalformedInputException;
4849
import java.util.Arrays;
50+
import java.util.Iterator;
4951
import java.util.List;
5052
import java.util.concurrent.atomic.AtomicBoolean;
5153
import java.util.concurrent.atomic.AtomicInteger;
@@ -178,6 +180,16 @@ public void testSplit(String message, String regex, int limit, Observable<String
178180
AssertObservable.assertObservableEqualsBlocking("when input is " + message
179181
+ " and limit = " + limit, exp, act);
180182
}
183+
184+
@Test
185+
public void testSplitLongPattern() {
186+
Iterator<String> iter = StringObservable.split(Observable.just("asdfqw","erasdf"), "qwer").toBlocking().getIterator();
187+
assertTrue(iter.hasNext());
188+
assertEquals("asdf", iter.next());
189+
assertTrue(iter.hasNext());
190+
assertEquals("asdf", iter.next());
191+
assertFalse(iter.hasNext());
192+
}
181193

182194
@Test
183195
public void testJoinMixed() {

0 commit comments

Comments
 (0)