diff --git a/jetty-http/src/test/java/org/eclipse/jetty/http/MultiPartParserTest.java b/jetty-http/src/test/java/org/eclipse/jetty/http/MultiPartParserTest.java index 965e86618a1..0added79b5f 100644 --- a/jetty-http/src/test/java/org/eclipse/jetty/http/MultiPartParserTest.java +++ b/jetty-http/src/test/java/org/eclipse/jetty/http/MultiPartParserTest.java @@ -23,7 +23,9 @@ import static org.junit.Assert.*; import java.nio.ByteBuffer; import java.util.ArrayList; +import java.util.Arrays; import java.util.List; +import java.util.concurrent.ThreadLocalRandom; import org.eclipse.jetty.http.MultiPartParser.State; import org.eclipse.jetty.util.BufferUtil; @@ -291,8 +293,6 @@ public class MultiPartParserTest assertThat(data.remaining(),is(0)); assertThat(handler.fields,Matchers.contains("name: value", "<>")); assertThat(handler.content,Matchers.contains("Hello","<>")); - - } @@ -346,7 +346,40 @@ public class MultiPartParserTest + "How now brown cow.\n" + "The quick brown fox jumped over the lazy dog.\n","<>")); } + + @Test + public void testBinaryPart() + { + byte[] random = new byte[8192]; + final ByteBuffer bytes = BufferUtil.allocate(random.length); + ThreadLocalRandom.current().nextBytes(random); + // Arrays.fill(random,(byte)'X'); + + TestHandler handler = new TestHandler() + { + @Override + public boolean content(ByteBuffer buffer, boolean last) + { + BufferUtil.append(bytes,buffer); + return last; + } + }; + MultiPartParser parser = new MultiPartParser(handler,"BOUNDARY"); + + String preamble = "Blah blah blah\r\n--BOUNDARY\r\n\r\n"; + String epilogue = "\r\n--BOUNDARY\r\nBlah blah blah!\r\n"; + + ByteBuffer data = BufferUtil.allocate(preamble.length()+random.length+epilogue.length()); + BufferUtil.append(data,BufferUtil.toBuffer(preamble)); + BufferUtil.append(data,ByteBuffer.wrap(random)); + BufferUtil.append(data,BufferUtil.toBuffer(epilogue)); + + parser.parse(data,true); + assertThat(parser.getState(), is(State.DELIMITER)); + assertThat(data.remaining(),is(19)); + assertThat(bytes.array(),is(random)); + } @Test public void testEpilogue() { diff --git a/jetty-util/src/main/java/org/eclipse/jetty/util/SearchPattern.java b/jetty-util/src/main/java/org/eclipse/jetty/util/SearchPattern.java index 1b052dbc19b..ab894211247 100644 --- a/jetty-util/src/main/java/org/eclipse/jetty/util/SearchPattern.java +++ b/jetty-util/src/main/java/org/eclipse/jetty/util/SearchPattern.java @@ -78,7 +78,7 @@ public class SearchPattern for(int i = 0; i