Skip to content

Commit c7cfd85

Browse files
committed
Merge branch '2.9'
2 parents 5742c62 + f234258 commit c7cfd85

File tree

5 files changed

+45
-18
lines changed

5 files changed

+45
-18
lines changed

release-notes/VERSION

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,14 @@ Modules:
88
=== Releases ===
99
------------------------------------------------------------------------
1010

11+
2.9.4 (not yet released)
12+
13+
#62: SnakeYAML base64Coder is not OSGI exported
14+
(reported by mbechler@github)
15+
1116
2.9.3 (09-Dec-2017)
1217

13-
#39 (yamk): Binary data not recognized by YAML parser
18+
#39 (yaml): Binary data not recognized by YAML parser
1419
(repoted by tmoschou@github)
1520
#42 (csv): Add support for escaping double quotes with the configured escape character
1621
(contributed by frankgrimes97@github)

yaml/src/main/java/com/fasterxml/jackson/dataformat/yaml/YAMLGenerator.java

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
import org.yaml.snakeyaml.DumperOptions.FlowStyle;
1313
import org.yaml.snakeyaml.emitter.Emitter;
1414
import org.yaml.snakeyaml.events.*;
15-
import org.yaml.snakeyaml.external.biz.base64Coder.Base64Coder;
1615
import org.yaml.snakeyaml.nodes.Tag;
1716

1817
import com.fasterxml.jackson.core.*;
@@ -600,7 +599,7 @@ public void writeBinary(Base64Variant b64variant, byte[] data, int offset, int l
600599
if (offset > 0 || (offset+len) != data.length) {
601600
data = Arrays.copyOfRange(data, offset, offset+len);
602601
}
603-
_writeScalarBinary(data);
602+
_writeScalarBinary(b64variant, data);
604603
}
605604

606605
/*
@@ -774,10 +773,15 @@ protected void _writeScalar(String value, String type, Character style) throws I
774773
_emitter.emit(_scalarEvent(value, style));
775774
}
776775

777-
private void _writeScalarBinary(byte[] data) throws IOException
776+
private void _writeScalarBinary(Base64Variant b64variant,
777+
byte[] data) throws IOException
778778
{
779-
// 29-Nov-2017, tatu: Use SnakeYAML encoder instead of Jackson's
780-
String encoded = Base64Coder.encodeLines(data);
779+
// 15-Dec-2017, tatu: as per [dataformats-text#62], can not use SnakeYAML's internal
780+
// codec. Also: force use of linefeed variant if using default
781+
if (b64variant == Base64Variants.getDefaultVariant()) {
782+
b64variant = Base64Variants.MIME;
783+
}
784+
String encoded = b64variant.encode(data);
781785
_emitter.emit(new ScalarEvent(null, TAG_BINARY, EXPLICIT_TAGS, encoded,
782786
null, null, STYLE_BASE64));
783787
}

yaml/src/main/java/com/fasterxml/jackson/dataformat/yaml/YAMLParser.java

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77

88
import org.yaml.snakeyaml.error.Mark;
99
import org.yaml.snakeyaml.events.*;
10-
import org.yaml.snakeyaml.external.biz.base64Coder.Base64Coder;
1110
import org.yaml.snakeyaml.nodes.NodeId;
1211
import org.yaml.snakeyaml.nodes.Tag;
1312
import org.yaml.snakeyaml.parser.ParserImpl;
@@ -458,10 +457,16 @@ protected JsonToken _decodeScalar(ScalarEvent scalar) throws IOException
458457
}
459458
// [dataformats-text#39]: support binary type
460459
if ("binary".equals(typeTag)) {
461-
// 29-Nov-2017, tatu: two choices for base64 codecs (or 3 with Java 8):
462-
// Jackson's own or SnakeYAML. Former is faster, but maybe makes sense
463-
// to use latter for sake of consistency.
464-
_binaryValue = Base64Coder.decodeLines(value);
460+
// 15-Dec-2017, tatu: 2.9.4 uses Jackson's codec because SnakeYAML does
461+
// not export its codec via OSGi (breaking 2.9.3). Note that trailing
462+
// whitespace is ok with core 2.9.4, but not earlier, so we'll trim
463+
// on purpose here
464+
value = value.trim();
465+
try {
466+
_binaryValue = Base64Variants.MIME.decode(value);
467+
} catch (IllegalArgumentException e) {
468+
_reportError(e.getMessage());
469+
}
465470
return JsonToken.VALUE_EMBEDDED_OBJECT;
466471
}
467472
// canonical values by YAML are actually 'y' and 'n'; but plenty more unofficial:

yaml/src/test/java/com/fasterxml/jackson/dataformat/yaml/deser/BinaryReadTest.java

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package com.fasterxml.jackson.dataformat.yaml.deser;
22

3+
import java.io.IOException;
34
import java.util.Arrays;
45

56
import org.junit.Assert;
@@ -14,16 +15,21 @@ public class BinaryReadTest extends ModuleTestBase
1415

1516
public void testBinaryViaTree() throws Exception
1617
{
17-
final String BASE64 = " R0lGODlhDAAMAIQAAP//9/X\n"
18-
+" 17unp5WZmZgAAAOfn515eXv\n"
19-
+" Pz7Y6OjuDg4J+fn5OTk6enp\n"
20-
+" 56enmleECcgggoBADs=";
18+
final String BASE64 = " R0lGODlhDAAMAIQAAP//9/X1\n"
19+
+" 7unp5WZmZgAAAOfn515eXvPz\n"
20+
+" 7Y6OjuDg4J+fn5OTk6enp56e\n"
21+
+" nmleECcgggoBADs=";
2122
final String DOC = String.format(
2223
"---\n"
2324
+"picture: !!binary |\n"
2425
+"%s\n", BASE64);
25-
26-
final JsonNode bean = MAPPER.readTree(DOC);
26+
27+
JsonNode bean = null;
28+
try {
29+
bean = MAPPER.readTree(DOC);
30+
} catch (IOException e) {
31+
fail("Should have decoded properly, instead got "+e);
32+
}
2733
final JsonNode picture = bean.get("picture");
2834
assertNotNull(picture);
2935

yaml/src/test/java/com/fasterxml/jackson/dataformat/yaml/ser/DatabindWriteTest.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,14 @@ public void testBasicPOJO() throws Exception
3333
assertEquals("firstName: \"Bob\"", it.next());
3434
assertEquals("gender: \"MALE\"", it.next());
3535
assertEquals("lastName: \"Dabolito\"", it.next());
36-
assertEquals("userImage: !!binary |", it.next());
36+
// 15-Dec-2017, tatu: different linefeed modes, see f.ex:
37+
// https://stackoverflow.com/questions/3790454/in-yaml-how-do-i-break-a-string-over-multiple-lines
38+
String line = it.next();
39+
String expLine = "userImage: !!binary |";
40+
if (line.endsWith("|-")) {
41+
expLine += "-";
42+
}
43+
assertEquals(expLine, line);
3744
assertEquals("verified: false", it.next());
3845
assertFalse(it.hasNext());
3946
}

0 commit comments

Comments
 (0)