Skip to content
This repository was archived by the owner on May 14, 2025. It is now read-only.

Commit 502fc51

Browse files
authored
Use SafeConstuctor with SnakeYaml (#5049)
Fixes #5048
1 parent 60ece17 commit 502fc51

File tree

5 files changed

+24
-10
lines changed

5 files changed

+24
-10
lines changed

spring-cloud-dataflow-server-core/src/main/java/org/springframework/cloud/dataflow/server/service/impl/DefaultStreamService.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2017-2020 the original author or authors.
2+
* Copyright 2017-2022 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -13,6 +13,7 @@
1313
* See the License for the specific language governing permissions and
1414
* limitations under the License.
1515
*/
16+
1617
package org.springframework.cloud.dataflow.server.service.impl;
1718

1819
import java.util.ArrayList;
@@ -30,6 +31,8 @@
3031
import org.slf4j.LoggerFactory;
3132
import org.yaml.snakeyaml.DumperOptions;
3233
import org.yaml.snakeyaml.Yaml;
34+
import org.yaml.snakeyaml.constructor.SafeConstructor;
35+
import org.yaml.snakeyaml.representer.Representer;
3336

3437
import org.springframework.cloud.dataflow.audit.service.AuditRecordService;
3538
import org.springframework.cloud.dataflow.audit.service.AuditServiceUtils;
@@ -84,6 +87,7 @@
8487
* @author Christian Tzolov
8588
* @author Gunnar Hillert
8689
* @author Chris Schaefer
90+
* @author Chris Bono
8791
*/
8892
@Transactional
8993
public class DefaultStreamService implements StreamService {
@@ -349,7 +353,7 @@ String convertPropertiesToSkipperYaml(StreamDefinition streamDefinition,
349353
dumperOptions.setDefaultFlowStyle(DumperOptions.FlowStyle.BLOCK);
350354
dumperOptions.setPrettyFlow(true);
351355
dumperOptions.setLineBreak(DumperOptions.LineBreak.getPlatformLineBreak());
352-
Yaml yaml = new Yaml(dumperOptions);
356+
Yaml yaml = new Yaml(new SafeConstructor(), new Representer(dumperOptions), dumperOptions);
353357
return yaml.dump(skipperConfigValuesMap);
354358
}
355359
else {

spring-cloud-dataflow-server-core/src/main/java/org/springframework/cloud/dataflow/server/stream/SkipperStreamDeployer.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2017-2020 the original author or authors.
2+
* Copyright 2017-2022 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -41,6 +41,8 @@
4141
import org.slf4j.LoggerFactory;
4242
import org.yaml.snakeyaml.DumperOptions;
4343
import org.yaml.snakeyaml.Yaml;
44+
import org.yaml.snakeyaml.constructor.SafeConstructor;
45+
import org.yaml.snakeyaml.representer.Representer;
4446

4547
import org.springframework.cloud.dataflow.core.ApplicationType;
4648
import org.springframework.cloud.dataflow.core.DataFlowPropertyKeys;
@@ -100,6 +102,7 @@
100102
* @author Soby Chacko
101103
* @author Glenn Renfro
102104
* @author Christian Tzolov
105+
* @author Chris Bono
103106
*/
104107
public class SkipperStreamDeployer implements StreamDeployer {
105108

@@ -451,7 +454,7 @@ private Package createDependentPackage(String packageVersion, AppDeploymentReque
451454
dumperOptions.setDefaultScalarStyle(DumperOptions.ScalarStyle.DOUBLE_QUOTED);
452455
dumperOptions.setPrettyFlow(false);
453456
dumperOptions.setSplitLines(false);
454-
Yaml yaml = new Yaml(dumperOptions);
457+
Yaml yaml = new Yaml(new SafeConstructor(), new Representer(dumperOptions), dumperOptions);
455458
configValues.setRaw(yaml.dump(configValueMap));
456459

457460
pkg.setConfigValues(configValues);

spring-cloud-dataflow-server-core/src/test/java/org/springframework/cloud/dataflow/server/service/impl/DefaultStreamServiceIntegrationTests.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2017-2019 the original author or authors.
2+
* Copyright 2017-2022 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -13,6 +13,7 @@
1313
* See the License for the specific language governing permissions and
1414
* limitations under the License.
1515
*/
16+
1617
package org.springframework.cloud.dataflow.server.service.impl;
1718

1819
import java.io.IOException;
@@ -30,6 +31,8 @@
3031
import org.mockito.ArgumentCaptor;
3132
import org.yaml.snakeyaml.DumperOptions;
3233
import org.yaml.snakeyaml.Yaml;
34+
import org.yaml.snakeyaml.constructor.SafeConstructor;
35+
import org.yaml.snakeyaml.representer.Representer;
3336

3437
import org.springframework.beans.factory.annotation.Autowired;
3538
import org.springframework.boot.test.autoconfigure.jdbc.AutoConfigureTestDatabase;
@@ -77,6 +80,7 @@
7780
* @author Mark Pollack
7881
* @author Ilayaperumal Gopinathan
7982
* @author Christian Tzolov
83+
* @author Chris Bono
8084
*/
8185
@RunWith(SpringRunner.class)
8286
@SpringBootTest(classes = TestDependencies.class)
@@ -159,7 +163,7 @@ public void testInstallVersionOverride() throws IOException {
159163
DumperOptions dumperOptions = new DumperOptions();
160164
dumperOptions.setDefaultFlowStyle(DumperOptions.FlowStyle.BLOCK);
161165
dumperOptions.setPrettyFlow(true);
162-
Yaml yaml = new Yaml(dumperOptions);
166+
Yaml yaml = new Yaml(new SafeConstructor(), new Representer(dumperOptions), dumperOptions);
163167

164168
Object actualYamlLoaded = yaml.load(actualYaml);
165169
Object expectedYamlLoaded = yaml.load(expectedYaml);

spring-cloud-dataflow-server-core/src/test/java/org/springframework/cloud/dataflow/server/service/impl/DefaultStreamServiceUpdateTests.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2017-2019 the original author or authors.
2+
* Copyright 2017-2022 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -26,6 +26,8 @@
2626
import org.junit.runner.RunWith;
2727
import org.yaml.snakeyaml.DumperOptions;
2828
import org.yaml.snakeyaml.Yaml;
29+
import org.yaml.snakeyaml.constructor.SafeConstructor;
30+
import org.yaml.snakeyaml.representer.Representer;
2931

3032
import org.springframework.beans.factory.annotation.Autowired;
3133
import org.springframework.boot.test.autoconfigure.jdbc.AutoConfigureTestDatabase;
@@ -54,6 +56,7 @@
5456
* @author Christian Tzolov
5557
* @author Ilayaperumal Gopinathan
5658
* @author Gunnar Hillert
59+
* @author Chris Bono
5760
*/
5861
@RunWith(SpringRunner.class)
5962
@SpringBootTest(classes = TestDependencies.class)
@@ -124,7 +127,7 @@ public void testCreateUpdateRequests() throws IOException {
124127
DumperOptions dumperOptions = new DumperOptions();
125128
dumperOptions.setDefaultFlowStyle(DumperOptions.FlowStyle.BLOCK);
126129
dumperOptions.setPrettyFlow(true);
127-
Yaml yaml = new Yaml(dumperOptions);
130+
Yaml yaml = new Yaml(new SafeConstructor(), new Representer(dumperOptions), dumperOptions);
128131

129132
Object actualYamlLoaded = yaml.load(yml);
130133
Object expectedYamlLoaded = yaml.load(expectedYaml);

spring-cloud-dataflow-shell-core/src/main/java/org/springframework/cloud/dataflow/shell/command/support/YmlUtils.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717

1818
import io.codearte.props2yaml.Props2YAML;
1919
import org.yaml.snakeyaml.Yaml;
20+
import org.yaml.snakeyaml.constructor.SafeConstructor;
2021

2122
/**
2223
* Utility for converting a String of comma delimited property values to YAML.
@@ -30,9 +31,8 @@ public static String convertFromCsvToYaml(String propertiesAsString) {
3031
String stringToConvert = propertiesAsString.replaceAll(",", "\n");
3132
String yamlString = Props2YAML.fromContent(stringToConvert).convert();
3233
// validate the yaml can be parsed
33-
Yaml yaml = new Yaml();
34+
Yaml yaml = new Yaml(new SafeConstructor());
3435
yaml.load(yamlString);
3536
return yamlString;
3637
}
3738
}
38-

0 commit comments

Comments
 (0)