Skip to content

Commit 30a8ba0

Browse files
committed
Fixes #64 <where /> does not remove the first AND or OR if it's followed by a tab character.
1 parent 784af97 commit 30a8ba0

File tree

2 files changed

+27
-1
lines changed

2 files changed

+27
-1
lines changed

src/main/java/org/apache/ibatis/scripting/xmltags/WhereSqlNode.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
public class WhereSqlNode extends TrimSqlNode {
2121

2222
public WhereSqlNode(Configuration configuration, SqlNode contents) {
23-
super(configuration, contents, "WHERE", "AND |OR |AND\n|OR\n|AND\r|OR\r", null, null);
23+
super(configuration, contents, "WHERE", "AND |OR |AND\n|OR\n|AND\r|OR\r|AND\t|OR\t", null, null);
2424
}
2525

2626

src/test/java/org/apache/ibatis/builder/xml/dynamic/DynamicSqlSourceTest.java

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,19 @@ public void shouldTrimWHEREANDWithCRLFForFirstCondition() throws Exception {
173173
assertEquals(expected, boundSql.getSql());
174174
}
175175

176+
@Test
177+
public void shouldTrimWHEREANDWithTABForFirstCondition() throws Exception {
178+
final String expected = "SELECT * FROM BLOG WHERE \t ID = ?";
179+
DynamicSqlSource source = createDynamicSqlSource(
180+
new TextSqlNode("SELECT * FROM BLOG"),
181+
new WhereSqlNode(new Configuration(),mixedContents(
182+
new IfSqlNode(mixedContents(new TextSqlNode(" and\t ID = ? ")), "true"
183+
)
184+
)));
185+
BoundSql boundSql = source.getBoundSql(null);
186+
assertEquals(expected, boundSql.getSql());
187+
}
188+
176189
@Test
177190
public void shouldTrimWHEREORWithLFForFirstCondition() throws Exception {
178191
final String expected = "SELECT * FROM BLOG WHERE \n ID = ?";
@@ -199,6 +212,19 @@ public void shouldTrimWHEREORWithCRLFForFirstCondition() throws Exception {
199212
assertEquals(expected, boundSql.getSql());
200213
}
201214

215+
@Test
216+
public void shouldTrimWHEREORWithTABForFirstCondition() throws Exception {
217+
final String expected = "SELECT * FROM BLOG WHERE \t ID = ?";
218+
DynamicSqlSource source = createDynamicSqlSource(
219+
new TextSqlNode("SELECT * FROM BLOG"),
220+
new WhereSqlNode(new Configuration(),mixedContents(
221+
new IfSqlNode(mixedContents(new TextSqlNode(" or\t ID = ? ")), "true"
222+
)
223+
)));
224+
BoundSql boundSql = source.getBoundSql(null);
225+
assertEquals(expected, boundSql.getSql());
226+
}
227+
202228
@Test
203229
public void shouldTrimWHEREInsteadOfORForSecondCondition() throws Exception {
204230
final String expected = "SELECT * FROM BLOG WHERE NAME = ?";

0 commit comments

Comments
 (0)