Data URI error handling

pull/199/head
M66B 4 years ago
parent 7ff497b716
commit 6a769640b6

@ -327,7 +327,7 @@ class ImageHelper {
fitDrawable(d, a, scale, view); fitDrawable(d, a, scale, view);
return d; return d;
} catch (IllegalArgumentException ex) { } catch (IllegalArgumentException ex) {
Log.w(ex); Log.i(ex);
Drawable d = context.getDrawable(R.drawable.twotone_broken_image_24); Drawable d = context.getDrawable(R.drawable.twotone_broken_image_24);
d.setBounds(0, 0, px, px); d.setBounds(0, 0, px, px);
return d; return d;
@ -548,14 +548,18 @@ class ImageHelper {
// "5ErkJggg==\" alt=\"Red dot\" />"; // "5ErkJggg==\" alt=\"Red dot\" />";
// https://en.wikipedia.org/wiki/Data_URI_scheme // https://en.wikipedia.org/wiki/Data_URI_scheme
int comma = source.indexOf(','); try {
if (comma < 0) int comma = source.indexOf(',');
return null; if (comma < 0)
throw new IllegalArgumentException("Comma missing");
String base64 = source.substring(comma + 1);
byte[] bytes = Base64.decode(base64.getBytes(), 0); String base64 = source.substring(comma + 1);
byte[] bytes = Base64.decode(base64.getBytes(), 0);
return new ByteArrayInputStream(bytes); return new ByteArrayInputStream(bytes);
} catch (IllegalArgumentException ex) {
String excerpt = source.substring(0, Math.min(100, source.length()));
throw new IllegalArgumentException(excerpt, ex);
}
} }
private static Drawable getCachedImage(Context context, long id, String source) { private static Drawable getCachedImage(Context context, long id, String source) {

Loading…
Cancel
Save