parent
24ed6de6aa
commit
bdac39150f
|
@ -344,18 +344,18 @@ 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++) {
|
||||
|
||||
for (int i = 0; i < script.length(); i++) {
|
||||
char c = script.charAt(i);
|
||||
if (c == '\\') {
|
||||
inEscape = !inEscape;
|
||||
continue;
|
||||
}
|
||||
else if (inEscape) {
|
||||
if (inEscape) {
|
||||
inEscape = false;
|
||||
continue;
|
||||
}
|
||||
|
||||
// MySQL style escapes
|
||||
if (c == '\\') {
|
||||
inEscape = true;
|
||||
continue;
|
||||
}
|
||||
if (c == '\'') {
|
||||
inLiteral = !inLiteral;
|
||||
}
|
||||
|
@ -363,6 +363,7 @@ public abstract class ScriptUtils {
|
|||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2002-2016 the original author or authors.
|
||||
* Copyright 2002-2018 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
@ -166,12 +166,16 @@ public class ScriptUtilsUnitTests {
|
|||
public void containsDelimiters() {
|
||||
assertFalse(containsSqlScriptDelimiters("select 1\n select ';'", ";"));
|
||||
assertTrue(containsSqlScriptDelimiters("select 1; select 2", ";"));
|
||||
|
||||
assertFalse(containsSqlScriptDelimiters("select 1; select '\\n\n';", "\n"));
|
||||
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');", ";"));
|
||||
|
||||
// MySQL style escapes '\\'
|
||||
assertFalse(containsSqlScriptDelimiters("insert into users(first_name, last_name)\nvalues('a\\\\', 'b;')", ";"));
|
||||
assertTrue(containsSqlScriptDelimiters("insert into users(first_name, last_name)\nvalues('Charles', 'd\\'Artagnan'); select 1;", ";"));
|
||||
}
|
||||
|
||||
private String readScript(String path) throws Exception {
|
||||
|
|
Loading…
Reference in New Issue