Use SafeConstructor in Snakeyaml YAML constructors

This commit is contained in:
aboyko
2022-10-18 16:37:42 -04:00
parent cc001d62c3
commit 2d841f78fc
13 changed files with 38 additions and 18 deletions

View File

@@ -31,8 +31,8 @@ import org.springframework.ide.eclipse.editor.support.yaml.ast.NodeUtil;
import org.springframework.ide.eclipse.editor.support.yaml.ast.YamlASTProvider;
import org.springframework.ide.eclipse.editor.support.yaml.ast.YamlFileAST;
import org.springframework.ide.eclipse.editor.support.yaml.path.YamlPath;
import org.springframework.ide.eclipse.editor.support.yaml.path.YamlTraversal;
import org.yaml.snakeyaml.Yaml;
import org.yaml.snakeyaml.constructor.SafeConstructor;
import org.yaml.snakeyaml.nodes.Node;
import com.google.common.collect.ImmutableList;
@@ -293,7 +293,7 @@ public class RouteBuilderTest {
*/
private RouteAttributes parse(List<CFCloudDomain> domains, String manifestText) {
IDocument doc = new Document(manifestText);
YamlASTProvider parser = new YamlASTProvider(new Yaml());
YamlASTProvider parser = new YamlASTProvider(new Yaml(new SafeConstructor()));
YamlFileAST ast = parser.getAST(doc);
List<Node> names = YamlPath.EMPTY
.thenAnyChild()

View File

@@ -24,6 +24,7 @@ import org.springframework.ide.eclipse.boot.dash.cf.deployment.AppNameAnnotation
import org.springframework.ide.eclipse.boot.dash.cf.deployment.AppNameReconciler;
import org.springframework.ide.eclipse.editor.support.yaml.ast.YamlASTProvider;
import org.yaml.snakeyaml.Yaml;
import org.yaml.snakeyaml.constructor.SafeConstructor;
/**
* Tests for application name reconciler
@@ -34,7 +35,7 @@ import org.yaml.snakeyaml.Yaml;
public class AppNameReconcilerTest {
private void testAppNames(String manifest, String...expectedAppNames) throws Exception {
AppNameReconciler reconciler = new AppNameReconciler(new YamlASTProvider(new Yaml()));
AppNameReconciler reconciler = new AppNameReconciler(new YamlASTProvider(new Yaml(new SafeConstructor())));
AppNameAnnotationModel annotationModel = new AppNameAnnotationModel("test");
Document doc = new Document(manifest);
reconciler.reconcile(doc, annotationModel, new NullProgressMonitor());

View File

@@ -25,6 +25,8 @@ import org.yaml.snakeyaml.DumperOptions;
import org.yaml.snakeyaml.DumperOptions.FlowStyle;
import org.yaml.snakeyaml.DumperOptions.LineBreak;
import org.yaml.snakeyaml.Yaml;
import org.yaml.snakeyaml.constructor.SafeConstructor;
import org.yaml.snakeyaml.representer.Representer;
/**
* Tests for generating YAML files from {@link CloudApplicationDeploymentProperties}
@@ -44,7 +46,7 @@ public class DeploymentProperties2YamlTest {
options.setDefaultFlowStyle(FlowStyle.BLOCK);
options.setLineBreak(LineBreak.getPlatformLineBreak());
String generatedManifest = new Yaml(options).dump(map);
String generatedManifest = new Yaml(new SafeConstructor(), new Representer(options), options).dump(map);
File yamlFile = ManifestCompareMergeTests.getTestFile(expectedYamlFilePath);
FileInputStream inputStream = null;