From 5dbe9b9c95677f5f71bd14015fbf3f4fc9f98603 Mon Sep 17 00:00:00 2001 From: Ekaterina Tuzova Date: Fri, 11 Feb 2011 18:20:43 +0300 Subject: [PATCH] fixed PY-2915 Convert double-quoted string to single-quoted string: breaks code in case of escaped characters --- .../codeInsight/intentions/PyQuotedStringIntention.java | 8 ++++---- python/testData/intentions/afterQuotedString.py | 2 +- python/testData/intentions/beforeQuotedString.py | 2 +- python/testSrc/com/jetbrains/python/PyIntentionTest.java | 2 +- 4 files changed, 7 insertions(+), 7 deletions(-) diff --git a/python/src/com/jetbrains/python/codeInsight/intentions/PyQuotedStringIntention.java b/python/src/com/jetbrains/python/codeInsight/intentions/PyQuotedStringIntention.java index a0820bcbb1cc..b851ff0ff334 100644 --- a/python/src/com/jetbrains/python/codeInsight/intentions/PyQuotedStringIntention.java +++ b/python/src/com/jetbrains/python/codeInsight/intentions/PyQuotedStringIntention.java @@ -55,12 +55,12 @@ public class PyQuotedStringIntention extends BaseIntentionAction { if (string != null) { String stringText = string.getText(); if (stringText.startsWith("'") && stringText.endsWith("'")) { - String result = convertSingleToDoubleQuoted(stringText); + String result = convertSingleToDoubleQuoted(stringText.substring(1, stringText.length()-1)); PyStringLiteralExpression st = elementGenerator.createStringLiteralAlreadyEscaped(result); string.replace(st); } if (stringText.startsWith("\"") && stringText.endsWith("\"")) { - String result = convertDoubleToSingleQuoted(string.getStringValue()); + String result = convertDoubleToSingleQuoted(stringText); PyStringLiteralExpression st = elementGenerator.createStringLiteralAlreadyEscaped(result); string.replace(st); } @@ -85,7 +85,7 @@ public class PyQuotedStringIntention extends BaseIntentionAction { else if (ch == '\'') { stringBuilder.append("\\\'"); } - else if (ch == '\\') { + else if (ch == '\\' && charArr[i+1] == '\"') { skipNext = true; stringBuilder.append(charArr[i+1]); } @@ -115,7 +115,7 @@ public class PyQuotedStringIntention extends BaseIntentionAction { else if (ch == '"') { stringBuilder.append("\\\""); } - else if (ch == '\\') { + else if (ch == '\\' && charArr[i+1] == '\'') { skipNext = true; stringBuilder.append(charArr[i+1]); } diff --git a/python/testData/intentions/afterQuotedString.py b/python/testData/intentions/afterQuotedString.py index 895ef0f6d0cd..0519d382065b 100644 --- a/python/testData/intentions/afterQuotedString.py +++ b/python/testData/intentions/afterQuotedString.py @@ -1 +1 @@ -a = '\'Hello\' - said man.' \ No newline at end of file +a = '\'Hello\' - said man.\n Let\'s go.' \ No newline at end of file diff --git a/python/testData/intentions/beforeQuotedString.py b/python/testData/intentions/beforeQuotedString.py index 08104a0704cb..b164f96ae495 100644 --- a/python/testData/intentions/beforeQuotedString.py +++ b/python/testData/intentions/beforeQuotedString.py @@ -1 +1 @@ -a = "'Hello' - said man." \ No newline at end of file +a = "'Hello' - said man.\n Let's go." \ No newline at end of file diff --git a/python/testSrc/com/jetbrains/python/PyIntentionTest.java b/python/testSrc/com/jetbrains/python/PyIntentionTest.java index 8e735aa6b118..c39c3c0622ec 100644 --- a/python/testSrc/com/jetbrains/python/PyIntentionTest.java +++ b/python/testSrc/com/jetbrains/python/PyIntentionTest.java @@ -139,7 +139,7 @@ public class PyIntentionTest extends PyLightFixtureTestCase { assertNull(action); } - public void testQuotedString() { + public void testQuotedString() { //PY-2915 doTest(PyBundle.message("INTN.quoted.string.double.to.single")); }