[Parser] Fix OOM in parsing of incorrect string literals
^KT-46455 Fixed KT-34410 KT-46564
This commit is contained in:
committed by
TeamCityServer
parent
c284eab2dd
commit
3532ce7fbc
@@ -105,7 +105,7 @@ import static org.jetbrains.kotlin.lexer.KtTokens.*;
|
|||||||
IElementType tt = tt();
|
IElementType tt = tt();
|
||||||
if (recoverySet == null ||
|
if (recoverySet == null ||
|
||||||
recoverySet.contains(tt) ||
|
recoverySet.contains(tt) ||
|
||||||
tt == LBRACE || tt == RBRACE || tt == LONG_TEMPLATE_ENTRY_END ||
|
tt == LBRACE || tt == RBRACE ||
|
||||||
(recoverySet.contains(EOL_OR_SEMICOLON) && (eof() || tt == SEMICOLON || myBuilder.newlineBeforeCurrentToken()))) {
|
(recoverySet.contains(EOL_OR_SEMICOLON) && (eof() || tt == SEMICOLON || myBuilder.newlineBeforeCurrentToken()))) {
|
||||||
error(message);
|
error(message);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -682,7 +682,7 @@ public class KotlinExpressionParsing extends AbstractKotlinParsing {
|
|||||||
else if (!parseLiteralConstant()) {
|
else if (!parseLiteralConstant()) {
|
||||||
ok = false;
|
ok = false;
|
||||||
// TODO: better recovery if FIRST(element) did not match
|
// TODO: better recovery if FIRST(element) did not match
|
||||||
errorWithRecovery("Expecting an element", EXPRESSION_FOLLOW);
|
errorWithRecovery("Expecting an element", TokenSet.orSet(EXPRESSION_FOLLOW, TokenSet.create(LONG_TEMPLATE_ENTRY_END)));
|
||||||
}
|
}
|
||||||
|
|
||||||
return ok;
|
return ok;
|
||||||
|
|||||||
@@ -0,0 +1,6 @@
|
|||||||
|
// ISSUE: KT-46455
|
||||||
|
|
||||||
|
class A {
|
||||||
|
fun bar() =
|
||||||
|
x foo(*z) ?: "${z.joinToString()}"
|
||||||
|
}
|
||||||
@@ -0,0 +1,66 @@
|
|||||||
|
KtFile: kt46455.kt
|
||||||
|
PACKAGE_DIRECTIVE
|
||||||
|
<empty list>
|
||||||
|
IMPORT_LIST
|
||||||
|
<empty list>
|
||||||
|
PsiComment(EOL_COMMENT)('// ISSUE: KT-46455')
|
||||||
|
PsiWhiteSpace('\n\n')
|
||||||
|
CLASS
|
||||||
|
PsiElement(class)('class')
|
||||||
|
PsiWhiteSpace(' ')
|
||||||
|
PsiElement(IDENTIFIER)('A')
|
||||||
|
PsiWhiteSpace(' ')
|
||||||
|
CLASS_BODY
|
||||||
|
PsiElement(LBRACE)('{')
|
||||||
|
PsiWhiteSpace('\n ')
|
||||||
|
FUN
|
||||||
|
PsiElement(fun)('fun')
|
||||||
|
PsiWhiteSpace(' ')
|
||||||
|
PsiElement(IDENTIFIER)('bar')
|
||||||
|
VALUE_PARAMETER_LIST
|
||||||
|
PsiElement(LPAR)('(')
|
||||||
|
PsiElement(RPAR)(')')
|
||||||
|
PsiWhiteSpace(' ')
|
||||||
|
PsiElement(EQ)('=')
|
||||||
|
PsiWhiteSpace('\n ')
|
||||||
|
BINARY_EXPRESSION
|
||||||
|
REFERENCE_EXPRESSION
|
||||||
|
PsiElement(IDENTIFIER)('x')
|
||||||
|
PsiWhiteSpace(' ')
|
||||||
|
OPERATION_REFERENCE
|
||||||
|
PsiElement(IDENTIFIER)('foo')
|
||||||
|
BINARY_EXPRESSION
|
||||||
|
PARENTHESIZED
|
||||||
|
PsiElement(LPAR)('(')
|
||||||
|
PsiErrorElement:Expecting an expression
|
||||||
|
<empty list>
|
||||||
|
OPERATION_REFERENCE
|
||||||
|
PsiElement(MUL)('*')
|
||||||
|
REFERENCE_EXPRESSION
|
||||||
|
PsiElement(IDENTIFIER)('z')
|
||||||
|
PsiErrorElement:Expecting member declaration
|
||||||
|
PsiElement(RPAR)(')')
|
||||||
|
PsiWhiteSpace(' ')
|
||||||
|
PsiErrorElement:Expecting member declaration
|
||||||
|
PsiElement(ELVIS)('?:')
|
||||||
|
PsiWhiteSpace(' ')
|
||||||
|
PsiErrorElement:Expecting member declaration
|
||||||
|
PsiElement(OPEN_QUOTE)('"')
|
||||||
|
PsiErrorElement:Expecting member declaration
|
||||||
|
PsiElement(LONG_TEMPLATE_ENTRY_START)('${')
|
||||||
|
PsiErrorElement:Expecting member declaration
|
||||||
|
PsiElement(IDENTIFIER)('z')
|
||||||
|
PsiErrorElement:Expecting member declaration
|
||||||
|
PsiElement(DOT)('.')
|
||||||
|
PsiErrorElement:Expecting member declaration
|
||||||
|
PsiElement(IDENTIFIER)('joinToString')
|
||||||
|
PsiErrorElement:Expecting member declaration
|
||||||
|
PsiElement(LPAR)('(')
|
||||||
|
PsiErrorElement:Expecting member declaration
|
||||||
|
PsiElement(RPAR)(')')
|
||||||
|
PsiErrorElement:Expecting member declaration
|
||||||
|
PsiElement(LONG_TEMPLATE_ENTRY_END)('}')
|
||||||
|
PsiErrorElement:Expecting member declaration
|
||||||
|
PsiElement(CLOSING_QUOTE)('"')
|
||||||
|
PsiWhiteSpace('\n')
|
||||||
|
PsiElement(RBRACE)('}')
|
||||||
@@ -2787,6 +2787,11 @@ public class ParsingTestGenerated extends AbstractParsingTest {
|
|||||||
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/psi/stringTemplates"), Pattern.compile("^(.*)\\.kts?$"), null, true);
|
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/psi/stringTemplates"), Pattern.compile("^(.*)\\.kts?$"), null, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("kt46455.kt")
|
||||||
|
public void testKt46455() throws Exception {
|
||||||
|
runTest("compiler/testData/psi/stringTemplates/kt46455.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("RawStringsWithManyQuotes.kt")
|
@TestMetadata("RawStringsWithManyQuotes.kt")
|
||||||
public void testRawStringsWithManyQuotes() throws Exception {
|
public void testRawStringsWithManyQuotes() throws Exception {
|
||||||
runTest("compiler/testData/psi/stringTemplates/RawStringsWithManyQuotes.kt");
|
runTest("compiler/testData/psi/stringTemplates/RawStringsWithManyQuotes.kt");
|
||||||
|
|||||||
Reference in New Issue
Block a user