Skip to content

Commit 78c2ac8

Browse files
committed
http://code.google.com/p/mybatis/issues/detail?id=356 : added the possibility of skip variables substitution
1 parent b728137 commit 78c2ac8

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

src/main/java/org/apache/ibatis/parsing/GenericTokenParser.java

+10-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,16 @@ public String parse(String text) {
3737
if (end > start) {
3838
String before = after.substring(0, start);
3939
String content = after.substring(start + openToken.length(), end);
40-
String substitution = handler.handleToken(content);
40+
String substitution;
41+
42+
// check if variable has to be skipped
43+
if (start > 0 && text.charAt(start - 1) == '\\') {
44+
before = before.substring(0, before.length() - 1);
45+
substitution = new StringBuilder(openToken).append(content).append(closeToken).toString();
46+
} else {
47+
substitution = handler.handleToken(content);
48+
}
49+
4150
builder.append(before);
4251
builder.append(substitution);
4352
after = after.substring(end + closeToken.length());

src/test/java/org/apache/ibatis/parsing/GenericTokenParserTest.java

+8
Original file line numberDiff line numberDiff line change
@@ -67,4 +67,12 @@ public void shouldDemonstrateGenericTokenReplacement() {
6767
assertEquals("Hello } ${ this is a test.", parser.parse("Hello } ${ this is a test."));
6868
}
6969

70+
@Test
71+
public void shallNotInterpolateSkippedVaiables() {
72+
GenericTokenParser parser = new GenericTokenParser("${", "}", new VariableTokenHandler(new HashMap<String, String>()));
73+
74+
assertEquals("${skipped} variable", parser.parse("\\${skipped} variable"));
75+
assertEquals("This is a ${skipped} variable", parser.parse("This is a \\${skipped} variable"));
76+
}
77+
7078
}

0 commit comments

Comments
 (0)