-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix bugs in SQL
ScriptScanner
with big String literals and PostgreSQ…
…L identifiers (as introduced by #7646) (#7818) Co-authored-by: Eddú Meléndez Gonzales <eddu.melendez@gmail.com>
- Loading branch information
1 parent
d80ce60
commit b59888a
Showing
2 changed files
with
78 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
54 changes: 54 additions & 0 deletions
54
modules/database-commons/src/test/java/org/testcontainers/ext/ScriptScannerTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
package org.testcontainers.ext; | ||
|
||
import org.apache.commons.lang3.StringUtils; | ||
import org.junit.Test; | ||
|
||
import java.util.regex.Pattern; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
public class ScriptScannerTest { | ||
|
||
@Test | ||
public void testHugeStringLiteral() { | ||
String script = "/* a comment */ \"" + StringUtils.repeat('~', 10000) + "\";"; | ||
ScriptScanner scanner = scanner(script); | ||
assertThat(scanner.next()).isEqualTo(ScriptScanner.Lexem.COMMENT); | ||
assertThat(scanner.next()).isEqualTo(ScriptScanner.Lexem.WHITESPACE); | ||
assertThat(scanner.next()).isEqualTo(ScriptScanner.Lexem.QUOTED_STRING); | ||
assertThat(scanner.getCurrentMatch()).matches(Pattern.compile("\"~+\"")); | ||
} | ||
|
||
@Test | ||
public void testPgIdentifierWithDollarSigns() { | ||
ScriptScanner scanner = scanner( | ||
"this$is$a$valid$postgreSQL$identifier " + | ||
"$a$While this is a quoted string$a$$ --just followed by a dollar sign" | ||
); | ||
assertThat(scanner.next()).isEqualTo(ScriptScanner.Lexem.IDENTIFIER); | ||
assertThat(scanner.next()).isEqualTo(ScriptScanner.Lexem.WHITESPACE); | ||
assertThat(scanner.next()).isEqualTo(ScriptScanner.Lexem.QUOTED_STRING); | ||
assertThat(scanner.next()).isEqualTo(ScriptScanner.Lexem.OTHER); | ||
} | ||
|
||
@Test | ||
public void testQuotedLiterals() { | ||
ScriptScanner scanner = scanner("'this \\'is a literal' \"this \\\" is a literal\""); | ||
assertThat(scanner.next()).isEqualTo(ScriptScanner.Lexem.QUOTED_STRING); | ||
assertThat(scanner.getCurrentMatch()).isEqualTo("'this \\'is a literal'"); | ||
assertThat(scanner.next()).isEqualTo(ScriptScanner.Lexem.WHITESPACE); | ||
assertThat(scanner.next()).isEqualTo(ScriptScanner.Lexem.QUOTED_STRING); | ||
assertThat(scanner.getCurrentMatch()).isEqualTo("\"this \\\" is a literal\""); | ||
} | ||
|
||
private static ScriptScanner scanner(String script) { | ||
return new ScriptScanner( | ||
"dummy", | ||
script, | ||
ScriptUtils.DEFAULT_STATEMENT_SEPARATOR, | ||
ScriptUtils.DEFAULT_COMMENT_PREFIX, | ||
ScriptUtils.DEFAULT_BLOCK_COMMENT_START_DELIMITER, | ||
ScriptUtils.DEFAULT_BLOCK_COMMENT_END_DELIMITER | ||
); | ||
} | ||
} |