提交 bdac3915 编写于 作者: S Sam Brannen

Polish contribution

Issue: SPR-17120
上级 24ed6de6
......@@ -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;
if (inEscape) {
inEscape = false;
continue;
}
else if (inEscape) {
inEscape = false;
// MySQL style escapes
if (c == '\\') {
inEscape = true;
continue;
}
if (c == '\'') {
inLiteral = !inLiteral;
}
......@@ -363,6 +363,7 @@ public abstract class ScriptUtils {
return true;
}
}
return false;
}
......
/*
* 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 {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册