mirror of
https://github.com/vanitasvitae/Smack.git
synced 2024-11-22 12:02:05 +01:00
Delete XML whitespace before feeding the Base64 decoder
This commit is contained in:
parent
1bc8a22b28
commit
d7b7abc7eb
2 changed files with 12 additions and 2 deletions
|
@ -543,9 +543,15 @@ public class StringUtils {
|
|||
return cs.toString();
|
||||
}
|
||||
|
||||
private static final Pattern XMLWHITESPACE = Pattern.compile("[\t\n\r ]");
|
||||
/**
|
||||
* Defined by XML 1.0 § 2.3 as:
|
||||
* S ::= (#x20 | #x9 | #xD | #xA)+
|
||||
*
|
||||
* @see <a href="https://www.w3.org/TR/xml/#sec-white-space">XML 1.0 § 2.3</a>
|
||||
*/
|
||||
private static final Pattern XML_WHITESPACE = Pattern.compile("[\t\n\r ]");
|
||||
|
||||
public static String deleteXmlWhitespace(String string) {
|
||||
return XMLWHITESPACE.matcher(string).replaceAll("");
|
||||
return XML_WHITESPACE.matcher(string).replaceAll("");
|
||||
}
|
||||
}
|
||||
|
|
|
@ -19,6 +19,7 @@ package org.jivesoftware.smack.util.stringencoder;
|
|||
import java.nio.charset.StandardCharsets;
|
||||
|
||||
import org.jivesoftware.smack.util.Objects;
|
||||
import org.jivesoftware.smack.util.StringUtils;
|
||||
|
||||
public class Base64 {
|
||||
|
||||
|
@ -57,6 +58,9 @@ public class Base64 {
|
|||
// TODO: We really should not mask the IllegalArgumentException. But some unit test depend on this behavior, like
|
||||
// ibb.packet.DataPacketExtension.shouldReturnNullIfDataIsInvalid().
|
||||
public static final byte[] decode(String string) {
|
||||
// xs:base64Binary may include XML whitespace which we need to delete before feeding the string into the Base64
|
||||
// decoder. See also XML Schema Part 2: Datatypes Second Edition § 3.2.16.
|
||||
string = StringUtils.deleteXmlWhitespace(string);
|
||||
try {
|
||||
return base64encoder.decode(string);
|
||||
} catch (IllegalArgumentException e) {
|
||||
|
|
Loading…
Reference in a new issue