false positive on escaped backslash in string literal (PY-2994)

This commit is contained in:
Dmitry Jemerov
2011-03-23 16:53:29 +01:00
parent 31491c42a2
commit ac6c054c56
3 changed files with 7 additions and 1 deletions

View File

@@ -40,7 +40,8 @@ public class StringConstantAnnotator extends PyAnnotator {
private boolean checkQuotedString(ASTNode stringNode, String nodeText) { private boolean checkQuotedString(ASTNode stringNode, String nodeText) {
char firstQuote = nodeText.charAt(0); char firstQuote = nodeText.charAt(0);
int lastChar = nodeText.length()-1; int lastChar = nodeText.length()-1;
if (lastChar == 0 || nodeText.charAt(lastChar) != firstQuote || nodeText.charAt(lastChar-1) == '\\') { if (lastChar == 0 || nodeText.charAt(lastChar) != firstQuote ||
(nodeText.charAt(lastChar-1) == '\\' && (lastChar == 1 || nodeText.charAt(lastChar-2) != '\\'))) {
getHolder().createErrorAnnotation(stringNode, MISSING_Q + " [" + firstQuote + "]"); getHolder().createErrorAnnotation(stringNode, MISSING_Q + " [" + firstQuote + "]");
return true; return true;
} }

View File

@@ -0,0 +1 @@
str = 'a a \\'

View File

@@ -142,6 +142,10 @@ public class PythonHighlightingTest extends PyLightFixtureTestCase {
doTest(true, false); doTest(true, false);
} }
public void testEscapedBackslash() { // PY-2994
doTest(true, false);
}
public void testUnsupportedFeaturesInPython3() { public void testUnsupportedFeaturesInPython3() {
doTest(LanguageLevel.PYTHON30, true, false); doTest(LanguageLevel.PYTHON30, true, false);
} }