parent
24ed6de6aa
commit
bdac39150f
|
|
@ -344,18 +344,18 @@ public abstract class ScriptUtils {
|
||||||
public static boolean containsSqlScriptDelimiters(String script, String delim) {
|
public static boolean containsSqlScriptDelimiters(String script, String delim) {
|
||||||
boolean inLiteral = false;
|
boolean inLiteral = false;
|
||||||
boolean inEscape = 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);
|
char c = script.charAt(i);
|
||||||
if (c == '\\') {
|
if (inEscape) {
|
||||||
inEscape = !inEscape;
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
else if (inEscape) {
|
|
||||||
inEscape = false;
|
inEscape = false;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
// MySQL style escapes
|
||||||
|
if (c == '\\') {
|
||||||
|
inEscape = true;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
if (c == '\'') {
|
if (c == '\'') {
|
||||||
inLiteral = !inLiteral;
|
inLiteral = !inLiteral;
|
||||||
}
|
}
|
||||||
|
|
@ -363,6 +363,7 @@ public abstract class ScriptUtils {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
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");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
|
@ -166,12 +166,16 @@ public class ScriptUtilsUnitTests {
|
||||||
public void containsDelimiters() {
|
public void containsDelimiters() {
|
||||||
assertFalse(containsSqlScriptDelimiters("select 1\n select ';'", ";"));
|
assertFalse(containsSqlScriptDelimiters("select 1\n select ';'", ";"));
|
||||||
assertTrue(containsSqlScriptDelimiters("select 1; select 2", ";"));
|
assertTrue(containsSqlScriptDelimiters("select 1; select 2", ";"));
|
||||||
|
|
||||||
assertFalse(containsSqlScriptDelimiters("select 1; select '\\n\n';", "\n"));
|
assertFalse(containsSqlScriptDelimiters("select 1; select '\\n\n';", "\n"));
|
||||||
assertTrue(containsSqlScriptDelimiters("select 1\n select 2", "\n"));
|
assertTrue(containsSqlScriptDelimiters("select 1\n select 2", "\n"));
|
||||||
|
|
||||||
assertFalse(containsSqlScriptDelimiters("select 1\n select 2", "\n\n"));
|
assertFalse(containsSqlScriptDelimiters("select 1\n select 2", "\n\n"));
|
||||||
assertTrue(containsSqlScriptDelimiters("select 1\n\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;')", ";"));
|
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 {
|
private String readScript(String path) throws Exception {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue