Skip to content

Commit 2d841f7

Browse files
committed
Use SafeConstructor in Snakeyaml YAML constructors
1 parent cc001d6 commit 2d841f7

File tree

13 files changed

+38
-18
lines changed

13 files changed

+38
-18
lines changed

eclipse-extensions/org.springframework.ide.eclipse.boot.dash.cf/src/org/springframework/ide/eclipse/boot/dash/cf/deployment/ApplicationManifestHandler.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@
5050
import org.yaml.snakeyaml.DumperOptions.FlowStyle;
5151
import org.yaml.snakeyaml.Yaml;
5252
import org.yaml.snakeyaml.constructor.SafeConstructor;
53+
import org.yaml.snakeyaml.representer.Representer;
5354

5455
import com.google.common.collect.ImmutableList;
5556

@@ -386,7 +387,7 @@ public boolean create(IProgressMonitor monitor, CloudApplicationDeploymentProper
386387
options.setCanonical(false);
387388
options.setPrettyFlow(true);
388389
options.setDefaultFlowStyle(FlowStyle.BLOCK);
389-
Yaml yaml = new Yaml(options);
390+
Yaml yaml = new Yaml(new SafeConstructor(), new Representer(options), options);
390391
String manifestValue = yaml.dump(deploymentInfoYaml);
391392

392393
if (manifestValue == null) {

eclipse-extensions/org.springframework.ide.eclipse.boot.dash.cf/src/org/springframework/ide/eclipse/boot/dash/cf/deployment/ApplicationNameReconciler.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
import org.eclipse.jface.text.source.ISourceViewer;
1717
import org.springframework.ide.eclipse.editor.support.yaml.ast.YamlASTProvider;
1818
import org.yaml.snakeyaml.Yaml;
19+
import org.yaml.snakeyaml.constructor.SafeConstructor;
1920

2021
/**
2122
* Reconciler for Application names in CF deployment manifest YAML
@@ -29,7 +30,7 @@ public class ApplicationNameReconciler extends Reconciler {
2930

3031
public ApplicationNameReconciler() {
3132
super();
32-
YamlASTProvider parser = new YamlASTProvider(new Yaml());
33+
YamlASTProvider parser = new YamlASTProvider(new Yaml(new SafeConstructor()));
3334
strategy= new AppNameReconcilingStrategy(parser);
3435
this.setReconcilingStrategy(strategy, IDocument.DEFAULT_CONTENT_TYPE);
3536
}

eclipse-extensions/org.springframework.ide.eclipse.boot.dash.cf/src/org/springframework/ide/eclipse/boot/dash/cf/deployment/YamlGraphDeploymentProperties.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242
import org.yaml.snakeyaml.Yaml;
4343
import org.yaml.snakeyaml.composer.Composer;
4444
import org.yaml.snakeyaml.constructor.Constructor;
45+
import org.yaml.snakeyaml.constructor.SafeConstructor;
4546
import org.yaml.snakeyaml.nodes.MappingNode;
4647
import org.yaml.snakeyaml.nodes.Node;
4748
import org.yaml.snakeyaml.nodes.NodeTuple;
@@ -50,6 +51,7 @@
5051
import org.yaml.snakeyaml.nodes.Tag;
5152
import org.yaml.snakeyaml.parser.ParserImpl;
5253
import org.yaml.snakeyaml.reader.StreamReader;
54+
import org.yaml.snakeyaml.representer.Representer;
5355
import org.yaml.snakeyaml.resolver.Resolver;
5456

5557
import com.google.common.base.Objects;
@@ -98,7 +100,8 @@ private void initializeYaml(String appName) {
98100
appNode = (MappingNode) root;
99101
}
100102

101-
this.yaml = new Yaml(createDumperOptions());
103+
DumperOptions options = createDumperOptions();
104+
this.yaml = new Yaml(new SafeConstructor(), new Representer(options), options);
102105
}
103106

104107
private static MappingNode findAppNode(SequenceNode seq, String name) {
@@ -252,7 +255,7 @@ public MultiTextEdit getDifferences(DeploymentProperties props) {
252255
options.setPrettyFlow(true);
253256
options.setDefaultFlowStyle(FlowStyle.BLOCK);
254257
options.setLineBreak(LineBreak.getPlatformLineBreak());
255-
edits.addChild(new ReplaceEdit(0, content.length(), new Yaml(options).dump(obj)));
258+
edits.addChild(new ReplaceEdit(0, content.length(), new Yaml(new SafeConstructor(), new Representer(options), options).dump(obj)));
256259
} else {
257260
edit = addLineBreakIfMissing(applicationsValueNode.getEndMark().getIndex());
258261
if (edit != null) {

eclipse-extensions/org.springframework.ide.eclipse.boot.dash.cf/src/org/springframework/ide/eclipse/boot/dash/cf/dialogs/DeploymentPropertiesDialogModel.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,8 @@
5858
import org.springsource.ide.eclipse.commons.livexp.util.Log;
5959
import org.yaml.snakeyaml.DumperOptions;
6060
import org.yaml.snakeyaml.DumperOptions.FlowStyle;
61+
import org.yaml.snakeyaml.constructor.SafeConstructor;
62+
import org.yaml.snakeyaml.representer.Representer;
6163
import org.yaml.snakeyaml.Yaml;
6264

6365
@SuppressWarnings("restriction")
@@ -919,7 +921,7 @@ private String generateDefaultContent() {
919921
options.setCanonical(false);
920922
options.setPrettyFlow(true);
921923
options.setDefaultFlowStyle(FlowStyle.BLOCK);
922-
return new Yaml(options).dump(yaml);
924+
return new Yaml(new SafeConstructor(), new Representer(options), options).dump(yaml);
923925
}
924926

925927

eclipse-extensions/org.springframework.ide.eclipse.boot.dash.cf/src/org/springframework/ide/eclipse/boot/dash/cf/model/CloudFoundryBootDashModel.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,10 @@
103103
import org.springsource.ide.eclipse.commons.livexp.util.ExceptionUtil;
104104
import org.springsource.ide.eclipse.commons.livexp.util.Log;
105105
import org.springsource.ide.eclipse.commons.livexp.util.OldValueDisposer;
106+
import org.yaml.snakeyaml.DumperOptions;
106107
import org.yaml.snakeyaml.Yaml;
108+
import org.yaml.snakeyaml.constructor.SafeConstructor;
109+
import org.yaml.snakeyaml.representer.Representer;
107110

108111
import com.google.common.collect.ImmutableList;
109112
import com.google.common.collect.ImmutableSet;
@@ -557,6 +560,7 @@ public CloudApplicationDeploymentProperties resolveDeploymentProperties(CloudApp
557560
final String yamlContents = IOUtil.toString(manifestFile.getContents());
558561
String errorMessage = null;
559562
TextEdit edit = null;
563+
DumperOptions options = YamlGraphDeploymentProperties.createDumperOptions();
560564
try {
561565
YamlGraphDeploymentProperties yamlGraph = new YamlGraphDeploymentProperties(yamlContents, deploymentProperties.getAppName(), cloudData);
562566
MultiTextEdit me = yamlGraph.getDifferences(deploymentProperties);
@@ -568,13 +572,13 @@ public CloudApplicationDeploymentProperties resolveDeploymentProperties(CloudApp
568572
Log.log(e);
569573
errorMessage = "Failed to create text differences between local manifest file and deployment properties on CF. Merge with caution.";
570574
edit = new ReplaceEdit(0, yamlContents.length(),
571-
new Yaml(YamlGraphDeploymentProperties.createDumperOptions())
575+
new Yaml(new SafeConstructor(), new Representer(options), options)
572576
.dump(ApplicationManifestHandler.toYaml(deploymentProperties, cloudData)));
573577
} catch (Throwable t) {
574578
Log.log(t);
575579
errorMessage = "Failed to parse local manifest file YAML contents. Merge with caution.";
576580
edit = new ReplaceEdit(0, yamlContents.length(),
577-
new Yaml(YamlGraphDeploymentProperties.createDumperOptions())
581+
new Yaml(new SafeConstructor(), new Representer(options), options)
578582
.dump(ApplicationManifestHandler.toYaml(deploymentProperties, cloudData)));
579583
}
580584

eclipse-extensions/org.springframework.ide.eclipse.boot.dash.test/src/org/springframework/ide/eclipse/boot/dash/test/RouteBuilderTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,8 @@
3131
import org.springframework.ide.eclipse.editor.support.yaml.ast.YamlASTProvider;
3232
import org.springframework.ide.eclipse.editor.support.yaml.ast.YamlFileAST;
3333
import org.springframework.ide.eclipse.editor.support.yaml.path.YamlPath;
34-
import org.springframework.ide.eclipse.editor.support.yaml.path.YamlTraversal;
3534
import org.yaml.snakeyaml.Yaml;
35+
import org.yaml.snakeyaml.constructor.SafeConstructor;
3636
import org.yaml.snakeyaml.nodes.Node;
3737

3838
import com.google.common.collect.ImmutableList;
@@ -293,7 +293,7 @@ private void assertRoutes(List<CFCloudDomain> domains, String manifestText, Stri
293293
*/
294294
private RouteAttributes parse(List<CFCloudDomain> domains, String manifestText) {
295295
IDocument doc = new Document(manifestText);
296-
YamlASTProvider parser = new YamlASTProvider(new Yaml());
296+
YamlASTProvider parser = new YamlASTProvider(new Yaml(new SafeConstructor()));
297297
YamlFileAST ast = parser.getAST(doc);
298298
List<Node> names = YamlPath.EMPTY
299299
.thenAnyChild()

eclipse-extensions/org.springframework.ide.eclipse.boot.dash.test/src/org/springframework/ide/eclipse/boot/dash/test/yaml/AppNameReconcilerTest.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
import org.springframework.ide.eclipse.boot.dash.cf.deployment.AppNameReconciler;
2525
import org.springframework.ide.eclipse.editor.support.yaml.ast.YamlASTProvider;
2626
import org.yaml.snakeyaml.Yaml;
27+
import org.yaml.snakeyaml.constructor.SafeConstructor;
2728

2829
/**
2930
* Tests for application name reconciler
@@ -34,7 +35,7 @@
3435
public class AppNameReconcilerTest {
3536

3637
private void testAppNames(String manifest, String...expectedAppNames) throws Exception {
37-
AppNameReconciler reconciler = new AppNameReconciler(new YamlASTProvider(new Yaml()));
38+
AppNameReconciler reconciler = new AppNameReconciler(new YamlASTProvider(new Yaml(new SafeConstructor())));
3839
AppNameAnnotationModel annotationModel = new AppNameAnnotationModel("test");
3940
Document doc = new Document(manifest);
4041
reconciler.reconcile(doc, annotationModel, new NullProgressMonitor());

eclipse-extensions/org.springframework.ide.eclipse.boot.dash.test/src/org/springframework/ide/eclipse/boot/dash/test/yaml/DeploymentProperties2YamlTest.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@
2525
import org.yaml.snakeyaml.DumperOptions.FlowStyle;
2626
import org.yaml.snakeyaml.DumperOptions.LineBreak;
2727
import org.yaml.snakeyaml.Yaml;
28+
import org.yaml.snakeyaml.constructor.SafeConstructor;
29+
import org.yaml.snakeyaml.representer.Representer;
2830

2931
/**
3032
* Tests for generating YAML files from {@link CloudApplicationDeploymentProperties}
@@ -44,7 +46,7 @@ private static void testDeploymentProperties(CloudApplicationDeploymentPropertie
4446
options.setDefaultFlowStyle(FlowStyle.BLOCK);
4547
options.setLineBreak(LineBreak.getPlatformLineBreak());
4648

47-
String generatedManifest = new Yaml(options).dump(map);
49+
String generatedManifest = new Yaml(new SafeConstructor(), new Representer(options), options).dump(map);
4850

4951
File yamlFile = ManifestCompareMergeTests.getTestFile(expectedYamlFilePath);
5052
FileInputStream inputStream = null;

eclipse-extensions/org.springframework.ide.eclipse.boot.refactoring/src/org/springframework/ide/eclipse/boot/refactoring/PropertiesToYamlConverter.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@
2525
import org.springframework.ide.eclipse.editor.support.yaml.path.YamlPathSegment.AtIndex;
2626
import org.yaml.snakeyaml.DumperOptions;
2727
import org.yaml.snakeyaml.Yaml;
28+
import org.yaml.snakeyaml.constructor.SafeConstructor;
29+
import org.yaml.snakeyaml.representer.Representer;
2830

2931
import com.google.common.collect.Multimap;
3032

@@ -159,7 +161,7 @@ public PropertiesToYamlConverter(Multimap<String, String> properties) {
159161
options.setDefaultFlowStyle(DumperOptions.FlowStyle.BLOCK);
160162
options.setPrettyFlow(true);
161163

162-
Yaml yaml = new Yaml(options);
164+
Yaml yaml = new Yaml(new SafeConstructor(), new Representer(options), options);
163165
this.output = yaml.dump(object);
164166
}
165167

eclipse-language-servers/org.springframework.ide.eclipse.editor.support/src/org/springframework/ide/eclipse/editor/support/yaml/AbstractYamlSourceViewerConfiguration.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@
4949
import org.springframework.ide.eclipse.editor.support.yaml.hover.YamlHoverInfoProvider;
5050
import org.springframework.ide.eclipse.editor.support.yaml.structure.YamlStructureProvider;
5151
import org.yaml.snakeyaml.Yaml;
52+
import org.yaml.snakeyaml.constructor.SafeConstructor;
5253

5354
/**
5455
* @author Kris De Volder
@@ -76,7 +77,7 @@ public abstract class AbstractYamlSourceViewerConfiguration extends YEditSourceV
7677

7778
private Provider<Shell> shellProvider;
7879
private final String DIALOG_SETTINGS_KEY = this.getClass().getName();
79-
private final YamlASTProvider astProvider = new YamlASTProvider(new Yaml());
80+
private final YamlASTProvider astProvider = new YamlASTProvider(new Yaml(new SafeConstructor()));
8081
private YamlCompletionEngine completionEngine;
8182
protected ForceableReconciler fReconciler;
8283

0 commit comments

Comments
 (0)