Use SafeConstructor in Snakeyaml YAML constructors
This commit is contained in:
@@ -50,6 +50,7 @@ import org.yaml.snakeyaml.DumperOptions;
|
||||
import org.yaml.snakeyaml.DumperOptions.FlowStyle;
|
||||
import org.yaml.snakeyaml.Yaml;
|
||||
import org.yaml.snakeyaml.constructor.SafeConstructor;
|
||||
import org.yaml.snakeyaml.representer.Representer;
|
||||
|
||||
import com.google.common.collect.ImmutableList;
|
||||
|
||||
@@ -386,7 +387,7 @@ public class ApplicationManifestHandler {
|
||||
options.setCanonical(false);
|
||||
options.setPrettyFlow(true);
|
||||
options.setDefaultFlowStyle(FlowStyle.BLOCK);
|
||||
Yaml yaml = new Yaml(options);
|
||||
Yaml yaml = new Yaml(new SafeConstructor(), new Representer(options), options);
|
||||
String manifestValue = yaml.dump(deploymentInfoYaml);
|
||||
|
||||
if (manifestValue == null) {
|
||||
|
||||
@@ -16,6 +16,7 @@ import org.eclipse.jface.text.reconciler.Reconciler;
|
||||
import org.eclipse.jface.text.source.ISourceViewer;
|
||||
import org.springframework.ide.eclipse.editor.support.yaml.ast.YamlASTProvider;
|
||||
import org.yaml.snakeyaml.Yaml;
|
||||
import org.yaml.snakeyaml.constructor.SafeConstructor;
|
||||
|
||||
/**
|
||||
* Reconciler for Application names in CF deployment manifest YAML
|
||||
@@ -29,7 +30,7 @@ public class ApplicationNameReconciler extends Reconciler {
|
||||
|
||||
public ApplicationNameReconciler() {
|
||||
super();
|
||||
YamlASTProvider parser = new YamlASTProvider(new Yaml());
|
||||
YamlASTProvider parser = new YamlASTProvider(new Yaml(new SafeConstructor()));
|
||||
strategy= new AppNameReconcilingStrategy(parser);
|
||||
this.setReconcilingStrategy(strategy, IDocument.DEFAULT_CONTENT_TYPE);
|
||||
}
|
||||
|
||||
@@ -42,6 +42,7 @@ import org.yaml.snakeyaml.DumperOptions.LineBreak;
|
||||
import org.yaml.snakeyaml.Yaml;
|
||||
import org.yaml.snakeyaml.composer.Composer;
|
||||
import org.yaml.snakeyaml.constructor.Constructor;
|
||||
import org.yaml.snakeyaml.constructor.SafeConstructor;
|
||||
import org.yaml.snakeyaml.nodes.MappingNode;
|
||||
import org.yaml.snakeyaml.nodes.Node;
|
||||
import org.yaml.snakeyaml.nodes.NodeTuple;
|
||||
@@ -50,6 +51,7 @@ import org.yaml.snakeyaml.nodes.SequenceNode;
|
||||
import org.yaml.snakeyaml.nodes.Tag;
|
||||
import org.yaml.snakeyaml.parser.ParserImpl;
|
||||
import org.yaml.snakeyaml.reader.StreamReader;
|
||||
import org.yaml.snakeyaml.representer.Representer;
|
||||
import org.yaml.snakeyaml.resolver.Resolver;
|
||||
|
||||
import com.google.common.base.Objects;
|
||||
@@ -98,7 +100,8 @@ public class YamlGraphDeploymentProperties implements DeploymentProperties {
|
||||
appNode = (MappingNode) root;
|
||||
}
|
||||
|
||||
this.yaml = new Yaml(createDumperOptions());
|
||||
DumperOptions options = createDumperOptions();
|
||||
this.yaml = new Yaml(new SafeConstructor(), new Representer(options), options);
|
||||
}
|
||||
|
||||
private static MappingNode findAppNode(SequenceNode seq, String name) {
|
||||
@@ -252,7 +255,7 @@ public class YamlGraphDeploymentProperties implements DeploymentProperties {
|
||||
options.setPrettyFlow(true);
|
||||
options.setDefaultFlowStyle(FlowStyle.BLOCK);
|
||||
options.setLineBreak(LineBreak.getPlatformLineBreak());
|
||||
edits.addChild(new ReplaceEdit(0, content.length(), new Yaml(options).dump(obj)));
|
||||
edits.addChild(new ReplaceEdit(0, content.length(), new Yaml(new SafeConstructor(), new Representer(options), options).dump(obj)));
|
||||
} else {
|
||||
edit = addLineBreakIfMissing(applicationsValueNode.getEndMark().getIndex());
|
||||
if (edit != null) {
|
||||
|
||||
@@ -58,6 +58,8 @@ import org.springsource.ide.eclipse.commons.livexp.util.ExceptionUtil;
|
||||
import org.springsource.ide.eclipse.commons.livexp.util.Log;
|
||||
import org.yaml.snakeyaml.DumperOptions;
|
||||
import org.yaml.snakeyaml.DumperOptions.FlowStyle;
|
||||
import org.yaml.snakeyaml.constructor.SafeConstructor;
|
||||
import org.yaml.snakeyaml.representer.Representer;
|
||||
import org.yaml.snakeyaml.Yaml;
|
||||
|
||||
@SuppressWarnings("restriction")
|
||||
@@ -919,7 +921,7 @@ public class DeploymentPropertiesDialogModel extends AbstractDisposable {
|
||||
options.setCanonical(false);
|
||||
options.setPrettyFlow(true);
|
||||
options.setDefaultFlowStyle(FlowStyle.BLOCK);
|
||||
return new Yaml(options).dump(yaml);
|
||||
return new Yaml(new SafeConstructor(), new Representer(options), options).dump(yaml);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -103,7 +103,10 @@ import org.springsource.ide.eclipse.commons.livexp.core.ObservableSet;
|
||||
import org.springsource.ide.eclipse.commons.livexp.util.ExceptionUtil;
|
||||
import org.springsource.ide.eclipse.commons.livexp.util.Log;
|
||||
import org.springsource.ide.eclipse.commons.livexp.util.OldValueDisposer;
|
||||
import org.yaml.snakeyaml.DumperOptions;
|
||||
import org.yaml.snakeyaml.Yaml;
|
||||
import org.yaml.snakeyaml.constructor.SafeConstructor;
|
||||
import org.yaml.snakeyaml.representer.Representer;
|
||||
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
@@ -557,6 +560,7 @@ public class CloudFoundryBootDashModel extends RemoteBootDashModel {
|
||||
final String yamlContents = IOUtil.toString(manifestFile.getContents());
|
||||
String errorMessage = null;
|
||||
TextEdit edit = null;
|
||||
DumperOptions options = YamlGraphDeploymentProperties.createDumperOptions();
|
||||
try {
|
||||
YamlGraphDeploymentProperties yamlGraph = new YamlGraphDeploymentProperties(yamlContents, deploymentProperties.getAppName(), cloudData);
|
||||
MultiTextEdit me = yamlGraph.getDifferences(deploymentProperties);
|
||||
@@ -568,13 +572,13 @@ public class CloudFoundryBootDashModel extends RemoteBootDashModel {
|
||||
Log.log(e);
|
||||
errorMessage = "Failed to create text differences between local manifest file and deployment properties on CF. Merge with caution.";
|
||||
edit = new ReplaceEdit(0, yamlContents.length(),
|
||||
new Yaml(YamlGraphDeploymentProperties.createDumperOptions())
|
||||
new Yaml(new SafeConstructor(), new Representer(options), options)
|
||||
.dump(ApplicationManifestHandler.toYaml(deploymentProperties, cloudData)));
|
||||
} catch (Throwable t) {
|
||||
Log.log(t);
|
||||
errorMessage = "Failed to parse local manifest file YAML contents. Merge with caution.";
|
||||
edit = new ReplaceEdit(0, yamlContents.length(),
|
||||
new Yaml(YamlGraphDeploymentProperties.createDumperOptions())
|
||||
new Yaml(new SafeConstructor(), new Representer(options), options)
|
||||
.dump(ApplicationManifestHandler.toYaml(deploymentProperties, cloudData)));
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user