Skip to content
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 @@ -247,6 +247,8 @@ private void handleWhenOtherwiseNodes(XNode chooseSqlNode, List<SqlNode> ifSqlNo
handler.handleNode(child, ifSqlNodes);
} else if (handler instanceof OtherwiseHandler) {
handler.handleNode(child, defaultSqlNodes);
} else {
throw new BuilderException("Unknown element <" + nodeName + "> in SQL statement.");
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@
package org.apache.ibatis.scripting.xmltags;

import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatThrownBy;

import org.apache.ibatis.builder.BuilderException;
import org.apache.ibatis.mapping.SqlSource;
import org.apache.ibatis.parsing.XPathParser;
import org.apache.ibatis.session.Configuration;
Expand All @@ -42,4 +44,19 @@ void shouldWhereInsertWhitespace() throws Exception {
.containsPattern("(?m)^\\s*select \\* from user\\s+WHERE\\s+id = 1\\s+and id > 0\\s*$");
}

@Test
void shouldThrowIfUnknownElementFound() {
String xml = """
<script>
select * from user
<choose>
<when test="1==1">and id = 1</when>
<otherwize>and id > 0</otherwize>
</choose>
</script>
""";
XMLScriptBuilder parser = new XMLScriptBuilder(new Configuration(), new XPathParser(xml).evalNode("/script"));
assertThatThrownBy(parser::parseScriptNode).isInstanceOf(BuilderException.class)
.hasMessage("Unknown element <otherwize> in SQL statement.");
}
}