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

Fix various encoding problems with config 10895 #10900

Draft
wants to merge 5 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -34,6 +34,7 @@
import javax.xml.transform.stream.StreamSource;
import java.io.*;
import java.net.URL;
import java.nio.charset.StandardCharsets;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.List;
Expand Down Expand Up @@ -106,7 +107,7 @@ public String upgrade(String content, int currentVersion, int targetVersion) {
private void validate(String content) {
int currentVersion = getCurrentSchemaVersion(content);
try {
buildXmlDocument(new ByteArrayInputStream(content.getBytes()), GoConfigSchema.getResource(currentVersion), registry.xsds());
buildXmlDocument(new ByteArrayInputStream(content.getBytes(StandardCharsets.UTF_8)), GoConfigSchema.getResource(currentVersion), registry.xsds());
} catch (Exception e) {
throw bomb("Cruise config file with version " + currentVersion + " is invalid. Unable to upgrade.", e);
}
Expand Down Expand Up @@ -160,7 +161,7 @@ private void tryIncreaseXpathExpressionOperationLimit(TransformerFactory factory
private int getCurrentSchemaVersion(String content) {
try {
SAXBuilder builder = new SAXBuilder();
Document document = builder.build(new ByteArrayInputStream(content.getBytes()));
Document document = builder.build(new ByteArrayInputStream(content.getBytes(StandardCharsets.UTF_8)));
Element root = document.getRootElement();

String currentVersion = root.getAttributeValue(schemaVersion) == null ? "0" : root.getAttributeValue(schemaVersion);
Expand Down
Expand Up @@ -108,7 +108,7 @@ public GoConfigHolder loadConfigHolder(final String content) throws Exception {

public CruiseConfig deserializeConfig(String content) throws Exception {
String md5 = md5Hex(content);
Element element = parseInputStream(new ByteArrayInputStream(content.getBytes()));
Element element = parseInputStream(new ByteArrayInputStream(content.getBytes(UTF_8)));
LOGGER.debug("[Config Save] Updating config cache with new XML");

CruiseConfig configForEdit = classParser(element, BasicCruiseConfig.class, configCache, new GoCipher(), registry, new ConfigReferenceElements()).parse();
Expand Down
Expand Up @@ -21,8 +21,6 @@
import java.io.File;
import java.io.IOException;

import static java.nio.charset.StandardCharsets.UTF_8;

public class GoConfigFileReader {
private final SystemEnvironment systemEnvironment;

Expand All @@ -31,7 +29,8 @@ public GoConfigFileReader(SystemEnvironment systemEnvironment) {
}

public String configXml() throws IOException {
return FileUtils.readFileToString(fileLocation(), UTF_8);
// readFileToString doesn't work with StandardCharsets
return FileUtils.readFileToString(fileLocation(), "UTF-8");
}

public File fileLocation() {
Expand Down
Expand Up @@ -407,7 +407,7 @@ public String configAsXml(CruiseConfig config, boolean skipPreprocessingAndValid
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
magicalGoConfigXmlWriter.write(config, outputStream, skipPreprocessingAndValidation);
LOGGER.debug("[Config Save] === Done converting config to XML");
return outputStream.toString();
return outputStream.toString(StandardCharsets.UTF_8);
}

public String getFileLocation() {
Expand Down