Skip to content

Commit

Permalink
Fix #1425
Browse files Browse the repository at this point in the history
  • Loading branch information
cowtowncoder committed Nov 26, 2016
1 parent 267abe1 commit 50a3d3e
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
import com.fasterxml.jackson.core.io.CharTypes;
import com.fasterxml.jackson.core.io.NumberInput;
import com.fasterxml.jackson.core.util.ByteArrayBuilder;

import com.fasterxml.jackson.databind.SerializerProvider;
import com.fasterxml.jackson.databind.exc.InvalidFormatException;
import com.fasterxml.jackson.databind.util.ClassUtil;

/**
* Value node that contains a text value.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
package com.fasterxml.jackson.databind.deser.jdk;

import java.nio.charset.StandardCharsets;

import com.fasterxml.jackson.databind.*;
import com.fasterxml.jackson.databind.exc.InputMismatchException;

// Mostly for [databind#1425]; not in optimal place (as it also has
// tree-access tests), but has to do for now
public class BaseDecodingTest extends BaseMapTest
{
private final ObjectMapper MAPPER = objectMapper();

private final byte[] HELLO_BYTES = "hello".getBytes(StandardCharsets.UTF_8);
private final String BASE64_HELLO = "aGVsbG8=";

// for [databind#1425]
public void testInvalidBase64() throws Exception
{
byte[] b = MAPPER.readValue(quote(BASE64_HELLO), byte[].class);
assertEquals(HELLO_BYTES, b);

_testInvalidBase64(MAPPER, BASE64_HELLO+"!");
_testInvalidBase64(MAPPER, BASE64_HELLO+"!!");
}

private void _testInvalidBase64(ObjectMapper mapper, String value) throws Exception
{
// First, use data-binding
try {
MAPPER.readValue(quote(value), byte[].class);
fail("Should not pass");
} catch (InputMismatchException e) {
verifyException(e, "Failed to decode");
verifyException(e, "as base64");
verifyException(e, "Illegal character '!'");
}

// and then tree model
JsonNode tree = mapper.readTree(String.format("{\"foo\":\"%s\"}", value));
JsonNode nodeValue = tree.get("foo");
try {
/*byte[] b =*/ nodeValue.binaryValue();
fail("Should not pass");
} catch (InputMismatchException e) {
verifyException(e, "Can not access contents of TextNode as binary");
verifyException(e, "Illegal character '!'");
}
}
}

0 comments on commit 50a3d3e

Please sign in to comment.