mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
PY-11481 Correctly detect escaped quotes at the end of string literals
This commit is contained in:
@@ -58,9 +58,17 @@ public class StringLiteralQuotesAnnotator extends PyAnnotator {
|
||||
|
||||
private boolean checkQuotedString(@NotNull ASTNode stringNode, @NotNull String nodeText) {
|
||||
final char firstQuote = nodeText.charAt(0);
|
||||
final int lastChar = nodeText.length() - 1;
|
||||
if (lastChar == 0 || nodeText.charAt(lastChar) != firstQuote ||
|
||||
(nodeText.charAt(lastChar - 1) == '\\' && (lastChar == 1 || nodeText.charAt(lastChar - 2) != '\\'))) {
|
||||
final char lastChar = nodeText.charAt(nodeText.length() - 1);
|
||||
int precedingBackslashCount = 0;
|
||||
for (int i = nodeText.length() - 2; i >= 0; i--) {
|
||||
if (nodeText.charAt(i) == '\\') {
|
||||
precedingBackslashCount++;
|
||||
}
|
||||
else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (nodeText.length() == 1 || lastChar != firstQuote || precedingBackslashCount % 2 != 0) {
|
||||
getHolder().createErrorAnnotation(stringNode, PyBundle.message("ANN.missing.closing.quote", firstQuote));
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,2 @@
|
||||
S1 = 'This literal contains even number of backslashes\\\\\\'
|
||||
S2 = <error descr="Missing closing quote [']">'This literal contains odd number of backslashes\\\\\\\'</error>
|
||||
@@ -174,6 +174,10 @@ public class PythonHighlightingTest extends PyTestCase {
|
||||
doTest(true, false);
|
||||
}
|
||||
|
||||
public void testMultipleEscapedBackslashes() {
|
||||
doTest(true, false);
|
||||
}
|
||||
|
||||
public void testUnsupportedFeaturesInPython3() {
|
||||
doTest(LanguageLevel.PYTHON30, true, false);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user