Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Percent-encoded data URLs support added #457

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@

import java.io.ByteArrayInputStream;
import java.io.InputStream;
import java.net.URLDecoder;
import java.nio.charset.StandardCharsets;
import java.util.Base64;
import java.util.logging.Level;

Expand All @@ -21,6 +23,9 @@ public static InputStream getEmbeddedBase64Data(@Nullable String uri) {
int b64Index = (uri!= null)? uri.indexOf("base64,") : -1;
if (b64Index != -1) {
String b64encoded = uri.substring(b64Index + "base64,".length());
if (b64encoded.contains("%")) {
b64encoded = URLDecoder.decode(b64encoded, StandardCharsets.US_ASCII);
}
return new ByteArrayInputStream( Base64.getDecoder().decode( b64encoded));
} else {
XRLog.load(Level.SEVERE, "Embedded css fonts must be encoded in base 64.");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@
import java.awt.image.BufferedImage;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.net.URLDecoder;
import java.nio.charset.StandardCharsets;
import java.util.Base64;
import java.util.Map;
import java.util.function.Consumer;
Expand Down Expand Up @@ -281,6 +283,9 @@ public static boolean isEmbeddedBase64Image(@Nullable String uri) {
int b64Index = imageDataUri.indexOf("base64,");
if (b64Index != -1) {
String b64encoded = imageDataUri.substring(b64Index + "base64,".length());
if (b64encoded.contains("%")) {
b64encoded = URLDecoder.decode(b64encoded, StandardCharsets.US_ASCII);
}
return Base64.getDecoder().decode(b64encoded);
} else {
XRLog.load(Level.SEVERE, "Embedded XHTML images must be encoded in base 64.");
Expand Down
Loading
Loading