From 1a73c9f0e3d33baec42c541769e9fc7e56af1da9 Mon Sep 17 00:00:00 2001 From: yanghaojia <2453883990@qq.com> Date: Fri, 13 Oct 2023 15:35:42 +0800 Subject: [PATCH] Fix JSONPath replace failed with line terminator --- .../conductor/core/utils/ParametersUtils.java | 3 ++- .../core/utils/ParametersUtilsTest.java | 24 +++++++++++++++++++ 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/core/src/main/java/com/netflix/conductor/core/utils/ParametersUtils.java b/core/src/main/java/com/netflix/conductor/core/utils/ParametersUtils.java index 1d8422bab1..15f8363f64 100644 --- a/core/src/main/java/com/netflix/conductor/core/utils/ParametersUtils.java +++ b/core/src/main/java/com/netflix/conductor/core/utils/ParametersUtils.java @@ -48,7 +48,8 @@ public class ParametersUtils { private static final Logger LOGGER = LoggerFactory.getLogger(ParametersUtils.class); private static final Pattern PATTERN = Pattern.compile( - "(?=(?> map = new TypeReference<>() {}; diff --git a/core/src/test/java/com/netflix/conductor/core/utils/ParametersUtilsTest.java b/core/src/test/java/com/netflix/conductor/core/utils/ParametersUtilsTest.java index eb2f239219..2f3c207514 100644 --- a/core/src/test/java/com/netflix/conductor/core/utils/ParametersUtilsTest.java +++ b/core/src/test/java/com/netflix/conductor/core/utils/ParametersUtilsTest.java @@ -257,6 +257,30 @@ public void testNestedPathExpressions() throws Exception { assertEquals(5, replaced.get("k3")); } + @Test + public void testReplaceWithLineTerminators() throws Exception { + Map map = new HashMap<>(); + map.put("name", "conductor"); + map.put("version", 2); + + Map input = new HashMap<>(); + input.put("k1", "Name: ${name}; Version: ${version};"); + input.put("k2", "Name: ${name};\nVersion: ${version};"); + input.put("k3", "Name: ${name};\rVersion: ${version};"); + input.put("k4", "Name: ${name};\r\nVersion: ${version};"); + + Object jsonObj = objectMapper.readValue(objectMapper.writeValueAsString(map), Object.class); + + Map replaced = parametersUtils.replace(input, jsonObj); + + assertNotNull(replaced); + + assertEquals("Name: conductor; Version: 2;", replaced.get("k1")); + assertEquals("Name: conductor;\nVersion: 2;", replaced.get("k2")); + assertEquals("Name: conductor;\rVersion: 2;", replaced.get("k3")); + assertEquals("Name: conductor;\r\nVersion: 2;", replaced.get("k4")); + } + @Test public void testReplaceWithEscapedTags() throws Exception { Map map = new HashMap<>();