File tree Expand file tree Collapse file tree 1 file changed +17
-1
lines changed Expand file tree Collapse file tree 1 file changed +17
-1
lines changed Original file line number Diff line number Diff line change @@ -1985,7 +1985,23 @@ static protected PImage parseBase64Image(String imagePath) {
19851985 String extension = parts [0 ].substring (11 );
19861986 String encodedData = parts [1 ];
19871987
1988- byte [] decodedBytes = Base64 .getDecoder ().decode (encodedData );
1988+ // If a SVG image has an error, the base 64 will fail, but the browser will work.
1989+ // So we are sanitizing the values before reading it.
1990+ // If you have any questions, please, read this
1991+ // reference: https://www.prostdev.com/post/understanding-the-illegal-base64-character-error-java-groovy-and-mule-4-dw-2-0
1992+ Base64 .Decoder decoder ;
1993+ if (encodedData .contains ("+" ) || encodedData .contains ("/" )) {
1994+ decoder = Base64 .getDecoder ();
1995+ encodedData = encodedData .replaceAll ("[^A-Za-z0-9+/=]" , "" );
1996+ } else if (encodedData .contains ("-" ) || encodedData .contains ("_" )) {
1997+ decoder = Base64 .getUrlDecoder ();
1998+ encodedData = encodedData .replaceAll ("[^A-Za-z0-9-_=]" , "" );
1999+ } else {
2000+ decoder = Base64 .getDecoder ();
2001+ encodedData = encodedData .replaceAll ("[^A-Za-z0-9+/=]" , "" );
2002+ }
2003+
2004+ byte [] decodedBytes = decoder .decode (encodedData );
19892005
19902006 if (decodedBytes == null ) {
19912007 System .err .println ("Decode Error on image: " + imagePath .substring (0 , 20 ));
You can’t perform that action at this time.
0 commit comments