From d33545bdce80934b96a73d541d876bddcbb07439 Mon Sep 17 00:00:00 2001 From: Sam Brannen Date: Mon, 17 May 2021 13:15:44 +0200 Subject: [PATCH] Avoid duplicate comment processing in ScriptUtils in spring-r2dbc See gh-26947 --- .../r2dbc/connection/init/ScriptUtils.java | 28 ++++++------------- 1 file changed, 8 insertions(+), 20 deletions(-) diff --git a/spring-r2dbc/src/main/java/org/springframework/r2dbc/connection/init/ScriptUtils.java b/spring-r2dbc/src/main/java/org/springframework/r2dbc/connection/init/ScriptUtils.java index 691a70458cd..f5fb828b6ef 100644 --- a/spring-r2dbc/src/main/java/org/springframework/r2dbc/connection/init/ScriptUtils.java +++ b/spring-r2dbc/src/main/java/org/springframework/r2dbc/connection/init/ScriptUtils.java @@ -242,7 +242,7 @@ public abstract class ScriptUtils { InputStreamReader in = (resource.getCharset() != null ? new InputStreamReader(is, resource.getCharset()) : new InputStreamReader(is)); LineNumberReader lnr = new LineNumberReader(in); - String script = readScript(lnr, commentPrefixes, separator, blockCommentEndDelimiter); + String script = readScript(lnr, separator); sink.next(script); sink.complete(); } @@ -256,34 +256,22 @@ public abstract class ScriptUtils { } /** - * Read a script from the provided {@code LineNumberReader}, using the supplied - * comment prefixes and statement separator, and build a {@code String} containing - * the lines. - *

Lines beginning with one of the comment prefixes are excluded - * from the results; however, line comments anywhere else — for example, - * within a statement — will be included in the results. + * Read a script from the provided {@code LineNumberReader} and build a + * {@code String} containing the lines. * @param lineNumberReader the {@code LineNumberReader} containing the script * to be processed - * @param commentPrefixes the prefixes that identify comments in the SQL script - * (typically "--") * @param separator the statement separator in the SQL script (typically ";") - * @param blockCommentEndDelimiter the end block comment delimiter * @return a {@code String} containing the script lines * @throws IOException in case of I/O errors */ - private static String readScript(LineNumberReader lineNumberReader, @Nullable String[] commentPrefixes, - @Nullable String separator, @Nullable String blockCommentEndDelimiter) throws IOException { - - String currentLine = lineNumberReader.readLine(); + private static String readScript(LineNumberReader lineNumberReader, @Nullable String separator) throws IOException { StringBuilder scriptBuilder = new StringBuilder(); + String currentLine = lineNumberReader.readLine(); while (currentLine != null) { - if ((blockCommentEndDelimiter != null && currentLine.contains(blockCommentEndDelimiter)) || - (commentPrefixes != null && !startsWithAny(currentLine, commentPrefixes, 0))) { - if (scriptBuilder.length() > 0) { - scriptBuilder.append('\n'); - } - scriptBuilder.append(currentLine); + if (scriptBuilder.length() > 0) { + scriptBuilder.append('\n'); } + scriptBuilder.append(currentLine); currentLine = lineNumberReader.readLine(); } appendSeparatorToScriptIfNecessary(scriptBuilder, separator);