-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Fix bugs in SQLScriptScanner
with big String literals and PostgreSQL identifiers (as introduced by #7646)
#7818
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
eddumelendez
merged 5 commits into
testcontainers:main
from
inponomarev:fix-scriptutils-2
Nov 17, 2023
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
46f03d2
fix bugs introduced by #7646
inponomarev a8bb7ac
remove erroneously committed file
inponomarev 13ea394
Apply suggestions from code review
eddumelendez d0230c9
Update modules/database-commons/src/test/java/org/testcontainers/ext/…
eddumelendez 49a2094
Fix format
eddumelendez File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 | ||
); | ||
} | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.