Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow Environment to resolve multiline strings. #608

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading