Skip to content

Commit d5040bc

Browse files
committed
PDFBOX-5660: avoid default encoding
git-svn-id: https://svn.apache.org/repos/asf/pdfbox/trunk@1927170 13f79535-47bb-0310-9956-ffa450edef68
1 parent a84a757 commit d5040bc

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

pdfbox/src/main/java/org/apache/pdfbox/pdmodel/fdf/FDFAnnotationStamp.java

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ public FDFAnnotationStamp(Element element) throws IOException
116116
}
117117
if (base64EncodedAppearance != null && !base64EncodedAppearance.isEmpty())
118118
{
119-
LOG.debug("Decoded XML: {}", () -> new String(decodedAppearanceXML, StandardCharsets.UTF_8));
119+
LOG.debug("Decoded XML:\n====\n{}\n====", () -> new String(decodedAppearanceXML, StandardCharsets.UTF_8));
120120

121121
Document stampAppearance = XMLUtil
122122
.parse(new ByteArrayInputStream(decodedAppearanceXML));
@@ -253,8 +253,16 @@ else if ("ASCII".equals(childEncodingAttr))
253253
{
254254
try (OutputStream os = stream.createOutputStream())
255255
{
256-
// not sure about charset
257-
os.write(child.getTextContent().getBytes());
256+
String encoding = child.getOwnerDocument().getXmlEncoding();
257+
if (encoding == null)
258+
{
259+
encoding = child.getOwnerDocument().getInputEncoding();
260+
}
261+
if (encoding == null)
262+
{
263+
encoding = "UTF-8";
264+
}
265+
os.write(child.getTextContent().getBytes(encoding));
258266
LOG.debug("{} => Data was streamed", parentAttrKey);
259267
}
260268
}

0 commit comments

Comments
 (0)