From d6edb027c3062f6a11d82f1482c78221c7ea9ec8 Mon Sep 17 00:00:00 2001 From: Jermaine Hua Date: Fri, 6 Dec 2024 02:36:08 +0800 Subject: [PATCH] [MNG-8388] Fix escape characters being replaced to change the original configuration (#1946) * [MNG-8388] Fix escape characters being replaced to change the original configuration Signed-off-by: crazyhzm * Add unit test --------- Signed-off-by: crazyhzm Co-authored-by: Guillaume Nodet --- .../apache/maven/internal/impl/model/DefaultInterpolator.java | 2 +- .../maven/internal/impl/model/DefaultInterpolatorTest.java | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/impl/maven-impl/src/main/java/org/apache/maven/internal/impl/model/DefaultInterpolator.java b/impl/maven-impl/src/main/java/org/apache/maven/internal/impl/model/DefaultInterpolator.java index 191b7f11f4..f73d876c90 100644 --- a/impl/maven-impl/src/main/java/org/apache/maven/internal/impl/model/DefaultInterpolator.java +++ b/impl/maven-impl/src/main/java/org/apache/maven/internal/impl/model/DefaultInterpolator.java @@ -420,7 +420,7 @@ public class DefaultInterpolator implements Interpolator { int escape = val.indexOf(ESCAPE_CHAR); while (escape >= 0 && escape < val.length() - 1) { char c = val.charAt(escape + 1); - if (c == '{' || c == '}' || c == ESCAPE_CHAR) { + if (c == '{' || c == '}') { val = val.substring(0, escape) + val.substring(escape + 1); } escape = val.indexOf(ESCAPE_CHAR, escape + 1); diff --git a/impl/maven-impl/src/test/java/org/apache/maven/internal/impl/model/DefaultInterpolatorTest.java b/impl/maven-impl/src/test/java/org/apache/maven/internal/impl/model/DefaultInterpolatorTest.java index ee77b5dc60..9a0c9c70a6 100644 --- a/impl/maven-impl/src/test/java/org/apache/maven/internal/impl/model/DefaultInterpolatorTest.java +++ b/impl/maven-impl/src/test/java/org/apache/maven/internal/impl/model/DefaultInterpolatorTest.java @@ -98,6 +98,7 @@ class DefaultInterpolatorTest { assertEquals("${a}", substVars("$\\{a${#}\\}", "b")); assertEquals("${a}", substVars("$\\{a\\}${#}", "b")); assertEquals("${a}", substVars("$\\{a\\}", "b")); + assertEquals("\\\\", substVars("\\\\", "b")); } @Test