From 2854ef2f56fd4d340996868bb297ac6965ea6dcd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9s=20Alcarraz?= Date: Thu, 25 Jul 2024 11:04:04 -0500 Subject: [PATCH] Allow Environment to resolve multiline strings. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Andrés Alcarraz --- .../main/java/org/jpos/core/Environment.java | 4 ++-- .../java/org/jpos/core/EnvironmentTest.java | 21 +++++++++++++++++++ 2 files changed, 23 insertions(+), 2 deletions(-) diff --git a/jpos/src/main/java/org/jpos/core/Environment.java b/jpos/src/main/java/org/jpos/core/Environment.java index 01f4471132..4b61de7017 100644 --- a/jpos/src/main/java/org/jpos/core/Environment.java +++ b/jpos/src/main/java/org/jpos/core/Environment.java @@ -37,8 +37,8 @@ public class Environment implements Loggeable { private static final String SYSTEM_PREFIX = "sys"; private static final String ENVIRONMENT_PREFIX = "env"; - private static Pattern valuePattern = Pattern.compile("^(.*)(\\$)([\\w]*)\\{([-!\\w.]+)(:(.*?))?\\}(.*)$"); - // make groups easier to read :-) 11112222233333333 4444444444455666665 7777 + private static Pattern valuePattern = Pattern.compile("^((?:.|\n|\r)*)(\\$)([\\w]*)\\{([-!\\w.]+)(:(.*?))?\\}((?:.|\n|\r)*)$"); + // make groups easier to read :-) 111111111111112222233333333 4444444444455666665 77777777777777 private static Pattern verbPattern = Pattern.compile("^\\$verb\\{([\\w\\W]+)\\}$"); private static Environment INSTANCE; diff --git a/jpos/src/test/java/org/jpos/core/EnvironmentTest.java b/jpos/src/test/java/org/jpos/core/EnvironmentTest.java index 13f381bfc0..e200058fd7 100644 --- a/jpos/src/test/java/org/jpos/core/EnvironmentTest.java +++ b/jpos/src/test/java/org/jpos/core/EnvironmentTest.java @@ -97,6 +97,27 @@ public void multiExpr() { assertEquals("the numbers UNO and DOS and NaN", Environment.get("the numbers ${test.one} and ${test.two} and ${test.three:NaN}")); } + + @Test + public void multiLineExpression() { + assertEquals("The next sentence is true\nThe previous sentence is false\n", + Environment.getEnvironment().getProperty("The next sentence is ${undefined-property:true}\n" + + "The previous sentence is ${undefined-property:false}\n")); + } + + @Test + public void multiLineExpressionWithCR() { + assertEquals("The next sentence is true\rThe previous sentence is false\r", + Environment.getEnvironment().getProperty("The next sentence is ${undefined-property:true}\r" + + "The previous sentence is ${undefined-property:false}\r")); + } + + @Test + public void multiLineExpressionWithCRLF() { + assertEquals("The next sentence is true\r\nThe previous sentence is false\r\n", + Environment.getEnvironment().getProperty("The next sentence is ${undefined-property:true}\r\n" + + "The previous sentence is ${undefined-property:false}\r\n")); + } @Test public void testNegateExprFromEnvironment() {