Skip to content

Commit

Permalink
Merge pull request #92 from rembjo0/topic-encoding
Browse files Browse the repository at this point in the history
Adds UTF-8 encoding when converting bytes to string
  • Loading branch information
pitbulk authored Feb 2, 2017
2 parents 26def30 + cb24c1b commit 560d41d
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ public SamlResponse(Saml2Settings settings, HttpRequest request) throws XPathExp
* @throws ValidationError
*/
public void loadXmlFromBase64(String responseStr) throws ParserConfigurationException, XPathExpressionException, SAXException, IOException, SettingsException, ValidationError {
samlResponseString = new String(Util.base64decoder(responseStr));
samlResponseString = new String(Util.base64decoder(responseStr), "UTF-8");
samlResponseDocument = Util.loadXML(samlResponseString);

if (samlResponseDocument == null) {
Expand Down
11 changes: 10 additions & 1 deletion core/src/main/java/com/onelogin/saml2/util/Util.java
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,16 @@ public static String convertDocumentToString(Document doc, Boolean c14n) {
} else {
XMLUtils.outputDOM(doc, baos);
}
return baos.toString();

return Util.toUtf8String(baos.toByteArray());
}

private static String toUtf8String(byte[] bytes) {
try {
return new String(bytes, "UTF-8");
} catch (UnsupportedEncodingException e) {
throw new IllegalStateException(e);
}
}

/**
Expand Down

0 comments on commit 560d41d

Please sign in to comment.