@Test public void testCrAsLineTermination() { TestHandler handler = new TestHandler() { @Override public boolean messageComplete() { return true; } @Override public boolean content(ByteBuffer buffer, boolean last) { super.content(buffer, last); return false; } }; MultiPartParser parser = new MultiPartParser(handler, "AaB03x"); ByteBuffer data = BufferUtils.toBuffer( "--AaB03x\r\n" + "content-disposition: form-data; name=\"field1\"\r\n" + "\r" + "Joe Blow\r\n" + "--AaB03x--\r\n"); BadMessageException x = assertThrows(BadMessageException.class, () -> parser.parse(data, true), "Invalid EOL"); assertTrue(x.getMessage().contains("Bad EOL")); }
public boolean parse(ByteBuffer buffer, boolean last) { boolean handle = false; while (!handle && BufferUtils.hasContent(buffer)) { switch (state) { case PREAMBLE: parsePreamble(buffer); continue; case DELIMITER: case DELIMITER_PADDING: case DELIMITER_CLOSE: parseDelimiter(buffer); continue; case BODY_PART: handle = parseMimePartHeaders(buffer); break; case FIRST_OCTETS: case OCTETS: handle = parseOctetContent(buffer); break; case EPILOGUE: BufferUtils.clear(buffer); break; case END: handle = true; break; default: throw new IllegalStateException(); } } if (last && BufferUtils.isEmpty(buffer)) { if (state == State.EPILOGUE) { state = State.END; if (LOG.isDebugEnabled()) LOG.debug("messageComplete {}", this); return handler.messageComplete(); } else { if (LOG.isDebugEnabled()) LOG.debug("earlyEOF {}", this); handler.earlyEOF(); return true; } } return handle; }
MultiPartParser { public boolean parse(ByteBuffer buffer, boolean last) { boolean handle = false; while (!handle && BufferUtils.hasContent(buffer)) { switch (state) { case PREAMBLE: parsePreamble(buffer); continue; case DELIMITER: case DELIMITER_PADDING: case DELIMITER_CLOSE: parseDelimiter(buffer); continue; case BODY_PART: handle = parseMimePartHeaders(buffer); break; case FIRST_OCTETS: case OCTETS: handle = parseOctetContent(buffer); break; case EPILOGUE: BufferUtils.clear(buffer); break; case END: handle = true; break; default: throw new IllegalStateException(); } } if (last && BufferUtils.isEmpty(buffer)) { if (state == State.EPILOGUE) { state = State.END; if (LOG.isDebugEnabled()) LOG.debug("messageComplete {}", this); return handler.messageComplete(); } else { if (LOG.isDebugEnabled()) LOG.debug("earlyEOF {}", this); handler.earlyEOF(); return true; } } return handle; } }
MultiPartParser { public boolean parse(ByteBuffer buffer, boolean last) { boolean handle = false; while (!handle && BufferUtils.hasContent(buffer)) { switch (state) { case PREAMBLE: parsePreamble(buffer); continue; case DELIMITER: case DELIMITER_PADDING: case DELIMITER_CLOSE: parseDelimiter(buffer); continue; case BODY_PART: handle = parseMimePartHeaders(buffer); break; case FIRST_OCTETS: case OCTETS: handle = parseOctetContent(buffer); break; case EPILOGUE: BufferUtils.clear(buffer); break; case END: handle = true; break; default: throw new IllegalStateException(); } } if (last && BufferUtils.isEmpty(buffer)) { if (state == State.EPILOGUE) { state = State.END; if (LOG.isDebugEnabled()) LOG.debug("messageComplete {}", this); return handler.messageComplete(); } else { if (LOG.isDebugEnabled()) LOG.debug("earlyEOF {}", this); handler.earlyEOF(); return true; } } return handle; } MultiPartParser(Handler handler, String boundary); }
MultiPartParser { public boolean parse(ByteBuffer buffer, boolean last) { boolean handle = false; while (!handle && BufferUtils.hasContent(buffer)) { switch (state) { case PREAMBLE: parsePreamble(buffer); continue; case DELIMITER: case DELIMITER_PADDING: case DELIMITER_CLOSE: parseDelimiter(buffer); continue; case BODY_PART: handle = parseMimePartHeaders(buffer); break; case FIRST_OCTETS: case OCTETS: handle = parseOctetContent(buffer); break; case EPILOGUE: BufferUtils.clear(buffer); break; case END: handle = true; break; default: throw new IllegalStateException(); } } if (last && BufferUtils.isEmpty(buffer)) { if (state == State.EPILOGUE) { state = State.END; if (LOG.isDebugEnabled()) LOG.debug("messageComplete {}", this); return handler.messageComplete(); } else { if (LOG.isDebugEnabled()) LOG.debug("earlyEOF {}", this); handler.earlyEOF(); return true; } } return handle; } MultiPartParser(Handler handler, String boundary); void reset(); Handler getHandler(); State getState(); boolean isState(State state); boolean parse(ByteBuffer buffer, boolean last); @Override String toString(); }
MultiPartParser { public boolean parse(ByteBuffer buffer, boolean last) { boolean handle = false; while (!handle && BufferUtils.hasContent(buffer)) { switch (state) { case PREAMBLE: parsePreamble(buffer); continue; case DELIMITER: case DELIMITER_PADDING: case DELIMITER_CLOSE: parseDelimiter(buffer); continue; case BODY_PART: handle = parseMimePartHeaders(buffer); break; case FIRST_OCTETS: case OCTETS: handle = parseOctetContent(buffer); break; case EPILOGUE: BufferUtils.clear(buffer); break; case END: handle = true; break; default: throw new IllegalStateException(); } } if (last && BufferUtils.isEmpty(buffer)) { if (state == State.EPILOGUE) { state = State.END; if (LOG.isDebugEnabled()) LOG.debug("messageComplete {}", this); return handler.messageComplete(); } else { if (LOG.isDebugEnabled()) LOG.debug("earlyEOF {}", this); handler.earlyEOF(); return true; } } return handle; } MultiPartParser(Handler handler, String boundary); void reset(); Handler getHandler(); State getState(); boolean isState(State state); boolean parse(ByteBuffer buffer, boolean last); @Override String toString(); static final LazyLogger LOG; }