[#5202] Correctly throw ErrorDataDecoderException when invalid encoded form parameters are present.
Motivation: At the moment we let the IllegalArgumentException escape when parsing form parameters. This is not expected. Modifications: Correctly catch IllegalArgumentException and rethrow as ErrorDataDecoderException. Result: Throw correct exception.
This commit is contained in:
parent
5aa87774a0
commit
c88761d1d9
@ -628,6 +628,10 @@ public class HttpPostStandardRequestDecoder implements InterfaceHttpPostRequestD
|
||||
// error while decoding
|
||||
undecodedChunk.readerIndex(firstpos);
|
||||
throw new ErrorDataDecoderException(e);
|
||||
} catch (IllegalArgumentException e) {
|
||||
// error while decoding
|
||||
undecodedChunk.readerIndex(firstpos);
|
||||
throw new ErrorDataDecoderException(e);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -23,6 +23,7 @@ import io.netty.handler.codec.DecoderResult;
|
||||
import io.netty.handler.codec.http.DefaultFullHttpRequest;
|
||||
import io.netty.handler.codec.http.DefaultHttpContent;
|
||||
import io.netty.handler.codec.http.DefaultHttpRequest;
|
||||
import io.netty.handler.codec.http.DefaultLastHttpContent;
|
||||
import io.netty.handler.codec.http.HttpContent;
|
||||
import io.netty.handler.codec.http.HttpHeaders;
|
||||
import io.netty.handler.codec.http.HttpMethod;
|
||||
@ -470,4 +471,21 @@ public class HttpPostRequestDecoderTest {
|
||||
req.release();
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFormEncodeIncorrect() throws Exception {
|
||||
LastHttpContent content = new DefaultLastHttpContent(
|
||||
Unpooled.copiedBuffer("project=netty&&project=netty", CharsetUtil.US_ASCII));
|
||||
DefaultHttpRequest req = new DefaultHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.POST, "/");
|
||||
HttpPostRequestDecoder decoder = new HttpPostRequestDecoder(req);
|
||||
try {
|
||||
decoder.offer(content);
|
||||
fail();
|
||||
} catch (HttpPostRequestDecoder.ErrorDataDecoderException e) {
|
||||
assertTrue(e.getCause() instanceof IllegalArgumentException);
|
||||
} finally {
|
||||
decoder.destroy();
|
||||
content.release();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user