Skip to content

Commit

Permalink
Allow Environment to resolve multiline strings.
Browse files Browse the repository at this point in the history
Signed-off-by: Andrés Alcarraz <[email protected]>
  • Loading branch information
alcarraz committed Jul 26, 2024
1 parent 584da0f commit e07018b
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 2 deletions.
4 changes: 2 additions & 2 deletions jpos/src/main/java/org/jpos/core/Environment.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,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;
Expand Down
21 changes: 21 additions & 0 deletions jpos/src/test/java/org/jpos/core/EnvironmentTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down

0 comments on commit e07018b

Please sign in to comment.