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

fixes #740 check escape backslash before appy quoteReplacement config #741

Merged
merged 1 commit into from
Jul 4, 2020
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,12 @@ public static Object getInjectValue(String string) {
if (!(value instanceof String)) {
return value;
}
m.appendReplacement(sb, m.quoteReplacement((String)value));
String valueStr = (String)value;
if(valueStr.contains("\\")) {
m.appendReplacement(sb, (String)value);
} else {
m.appendReplacement(sb, m.quoteReplacement((String)value));
}
}
return m.appendTail(sb).toString();
}
Expand Down
13 changes: 13 additions & 0 deletions config/src/test/java/com/networknt/config/ConfigEscapeTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,17 @@ public void testValuesEscape() {
Map<String, Object> passwordMap = Config.getInstance().getJsonMapConfigNoCache("password");
Assert.assertEquals("def$g", passwordMap.get("value"));
}

@Test
public void testSql1() {
Map<String, Object> passwordMap = Config.getInstance().getJsonMapConfigNoCache("password");
Assert.assertEquals("SELECT JSON_VALUE(abc, '$.foo.bar') FROM def", passwordMap.get("sql1"));
}

@Test
public void testSql2() {
Map<String, Object> passwordMap = Config.getInstance().getJsonMapConfigNoCache("password");
Assert.assertEquals("SELECT JSON_VALUE(abc, '$.foo.bar') FROM def", passwordMap.get("sql2"));
}

}
2 changes: 2 additions & 0 deletions config/src/test/resources/config/password.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,5 @@
# the config file not loaded properly. This is to reproduce the issue and get it fixed.
password: ${password:abc$defg}
value: ${password.escapeValue:abc$defg}
sql1: ${password.sql1:SELECT}
sql2: ${password.sql2:SELECT}
4 changes: 3 additions & 1 deletion config/src/test/resources/config/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,6 @@ TEST.map:
key2: element2
TEST.null:
TEST.emptyString: ""
password.escapeValue: def$g
password.escapeValue: def$g
password.sql1: SELECT JSON_VALUE(abc, '\$.foo.bar') FROM def
password.sql2: SELECT JSON_VALUE(abc, '$.foo.bar') FROM def