From 51538956d7d883ff4415a4bf9e1bdfa26e4d5371 Mon Sep 17 00:00:00 2001 From: Iwao AVE! Date: Wed, 21 Mar 2018 00:27:04 +0900 Subject: [PATCH] fixes #117 UNDO statement without a line break is ignored. --- .../apache/ibatis/migration/MigrationReader.java | 2 +- .../ibatis/migration/MigrationReaderTest.java | 13 +++++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/src/main/java/org/apache/ibatis/migration/MigrationReader.java b/src/main/java/org/apache/ibatis/migration/MigrationReader.java index 76260dde..c803f849 100644 --- a/src/main/java/org/apache/ibatis/migration/MigrationReader.java +++ b/src/main/java/org/apache/ibatis/migration/MigrationReader.java @@ -95,7 +95,7 @@ public int read(char[] cbuf, int off, int len) throws IOException { while (buffer.length() == 0) { int result = in.read(cbuf, off, len); if (result == -1) { - if (lineBuffer.length() > 0 && !undo && !inUndo) { + if (lineBuffer.length() > 0 && (!undo || inUndo)) { buffer.append(lineBuffer).append(lineSeparator); lineBuffer.setLength(0); } diff --git a/src/test/java/org/apache/ibatis/migration/MigrationReaderTest.java b/src/test/java/org/apache/ibatis/migration/MigrationReaderTest.java index 985f5fba..2025f2ee 100644 --- a/src/test/java/org/apache/ibatis/migration/MigrationReaderTest.java +++ b/src/test/java/org/apache/ibatis/migration/MigrationReaderTest.java @@ -72,6 +72,19 @@ public void shouldReturnUndoPart() throws Exception { // @formatter:on } + @Test + public void shouldReturnUndoPart_NoEndBreak() throws Exception { + // @formatter:off + String script = "-- comment\n" + + "do part\n" + + "--//@UNDO\n" + + "undo part"; + String result = readAsString(new MigrationReader(strToInputStream(script, charset), charset, true, null)); + assertEquals("-- @UNDO\n" + + "undo part\n", result); + // @formatter:on + } + @Test public void shouldUndoCommentBeLenient() throws Exception { // @formatter:off