From 7c3e56b62140897ece2cac404d8bba6f0e66d102 Mon Sep 17 00:00:00 2001 From: Tatu Saloranta Date: Fri, 25 Nov 2016 18:35:27 -0800 Subject: [PATCH] Fixed #335 --- .../java/com/fasterxml/jackson/core/Base64Variant.java | 8 ++------ .../fasterxml/jackson/core/base64/TestBase64Codec.java | 9 +++++++++ 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/src/main/java/com/fasterxml/jackson/core/Base64Variant.java b/src/main/java/com/fasterxml/jackson/core/Base64Variant.java index 84f27dc13d..5cddea5108 100644 --- a/src/main/java/com/fasterxml/jackson/core/Base64Variant.java +++ b/src/main/java/com/fasterxml/jackson/core/Base64Variant.java @@ -449,7 +449,7 @@ public byte[] decode(String input) throws IllegalArgumentException * assumption is that caller will ensure it is given in proper state, and * used as appropriate afterwards. * - * @since 2.2.3 + * @since 2.3 * * @throws IllegalArgumentException if input is not valid base64 encoded data */ @@ -458,16 +458,12 @@ public void decode(String str, ByteArrayBuilder builder) throws IllegalArgumentE int ptr = 0; int len = str.length(); - main_loop: while (ptr < len) { // first, we'll skip preceding white space, if any char ch; do { ch = str.charAt(ptr++); - if (ptr >= len) { - break main_loop; - } - } while (ch <= INT_SPACE); + } while ((ptr < len) && (ch <= INT_SPACE)); int bits = decodeBase64Char(ch); if (bits < 0) { _reportInvalidBase64(ch, 0, null); diff --git a/src/test/java/com/fasterxml/jackson/core/base64/TestBase64Codec.java b/src/test/java/com/fasterxml/jackson/core/base64/TestBase64Codec.java index 4b4b7b2459..dabcc39986 100644 --- a/src/test/java/com/fasterxml/jackson/core/base64/TestBase64Codec.java +++ b/src/test/java/com/fasterxml/jackson/core/base64/TestBase64Codec.java @@ -55,5 +55,14 @@ public void testErrors() throws Exception } catch (IllegalArgumentException iae) { verifyException(iae, "length must be exactly"); } + + // also, for [jackson-core#335] + final String BASE64_HELLO = "aGVsbG8=!"; + try { + Base64Variants.MIME.decode(BASE64_HELLO); + fail("Should not pass"); + } catch (IllegalArgumentException iae) { + verifyException(iae, "Illegal character"); + } } }