Add backslash escape support to containsSqlScriptDelimiters
Prior to this commit, ScriptUtils supported MySQL-style escapes ('\\') when splitting a script into statements; however, MySQL-style escapes were not supported when determining if a given script contained a specified statement delimiter. This caused executeSqlScript() to erroneously fallback to a newline as the statement separator in such cases. This commit fixes this issue by implementing the same check for MySQL-style escapes in containsSqlScriptDelimiters() that was already present in splitSqlScript(). Issue: SPR-17120
This commit is contained in:
parent
ac544924c8
commit
24ed6de6aa
|
@ -343,8 +343,20 @@ public abstract class ScriptUtils {
|
|||
*/
|
||||
public static boolean containsSqlScriptDelimiters(String script, String delim) {
|
||||
boolean inLiteral = false;
|
||||
boolean inEscape = false;
|
||||
for (int i = 0; i < script.length(); i++) {
|
||||
if (script.charAt(i) == '\'') {
|
||||
|
||||
char c = script.charAt(i);
|
||||
if (c == '\\') {
|
||||
inEscape = !inEscape;
|
||||
continue;
|
||||
}
|
||||
else if (inEscape) {
|
||||
inEscape = false;
|
||||
continue;
|
||||
}
|
||||
|
||||
if (c == '\'') {
|
||||
inLiteral = !inLiteral;
|
||||
}
|
||||
if (!inLiteral && script.startsWith(delim, i)) {
|
||||
|
|
|
@ -170,6 +170,8 @@ public class ScriptUtilsUnitTests {
|
|||
assertTrue(containsSqlScriptDelimiters("select 1\n select 2", "\n"));
|
||||
assertFalse(containsSqlScriptDelimiters("select 1\n select 2", "\n\n"));
|
||||
assertTrue(containsSqlScriptDelimiters("select 1\n\n select 2", "\n\n"));
|
||||
assertTrue(containsSqlScriptDelimiters("insert into users(first_name, last_name)\nvalues('Charles', 'd\\'Artagnan');", ";"));
|
||||
assertFalse(containsSqlScriptDelimiters("insert into users(first_name, last_name)\nvalues('a\\\\', 'b;')", ";"));
|
||||
}
|
||||
|
||||
private String readScript(String path) throws Exception {
|
||||
|
|
Loading…
Reference in New Issue