Skip to content

Commit 7c3e56b

Browse files
committed
Fixed #335
1 parent 7756869 commit 7c3e56b

File tree

2 files changed

+11
-6
lines changed

2 files changed

+11
-6
lines changed

src/main/java/com/fasterxml/jackson/core/Base64Variant.java

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -449,7 +449,7 @@ public byte[] decode(String input) throws IllegalArgumentException
449449
* assumption is that caller will ensure it is given in proper state, and
450450
* used as appropriate afterwards.
451451
*
452-
* @since 2.2.3
452+
* @since 2.3
453453
*
454454
* @throws IllegalArgumentException if input is not valid base64 encoded data
455455
*/
@@ -458,16 +458,12 @@ public void decode(String str, ByteArrayBuilder builder) throws IllegalArgumentE
458458
int ptr = 0;
459459
int len = str.length();
460460

461-
main_loop:
462461
while (ptr < len) {
463462
// first, we'll skip preceding white space, if any
464463
char ch;
465464
do {
466465
ch = str.charAt(ptr++);
467-
if (ptr >= len) {
468-
break main_loop;
469-
}
470-
} while (ch <= INT_SPACE);
466+
} while ((ptr < len) && (ch <= INT_SPACE));
471467
int bits = decodeBase64Char(ch);
472468
if (bits < 0) {
473469
_reportInvalidBase64(ch, 0, null);

src/test/java/com/fasterxml/jackson/core/base64/TestBase64Codec.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,5 +55,14 @@ public void testErrors() throws Exception
5555
} catch (IllegalArgumentException iae) {
5656
verifyException(iae, "length must be exactly");
5757
}
58+
59+
// also, for [jackson-core#335]
60+
final String BASE64_HELLO = "aGVsbG8=!";
61+
try {
62+
Base64Variants.MIME.decode(BASE64_HELLO);
63+
fail("Should not pass");
64+
} catch (IllegalArgumentException iae) {
65+
verifyException(iae, "Illegal character");
66+
}
5867
}
5968
}

0 commit comments

Comments
 (0)