From 98f6f3c003f3ccfa95af42349f5d9e4fb723a296 Mon Sep 17 00:00:00 2001 From: Ekaterina Tuzova Date: Thu, 14 Apr 2011 15:48:59 +0400 Subject: [PATCH] fixed PY-3295 "Convert single-quoted string to double-quoted string" intention changes the meaning of the code on escaped backslahes --- .../codeInsight/intentions/PyQuotedStringIntention.java | 4 ++-- python/testData/intentions/afterQuotedStringDoubleSlash.py | 1 + python/testData/intentions/beforeQuotedStringDoubleSlash.py | 1 + python/testSrc/com/jetbrains/python/PyIntentionTest.java | 4 ++++ 4 files changed, 8 insertions(+), 2 deletions(-) create mode 100644 python/testData/intentions/afterQuotedStringDoubleSlash.py create mode 100644 python/testData/intentions/beforeQuotedStringDoubleSlash.py diff --git a/python/src/com/jetbrains/python/codeInsight/intentions/PyQuotedStringIntention.java b/python/src/com/jetbrains/python/codeInsight/intentions/PyQuotedStringIntention.java index 56f6fb530ebf..9e82f66286f7 100644 --- a/python/src/com/jetbrains/python/codeInsight/intentions/PyQuotedStringIntention.java +++ b/python/src/com/jetbrains/python/codeInsight/intentions/PyQuotedStringIntention.java @@ -89,7 +89,7 @@ public class PyQuotedStringIntention extends BaseIntentionAction { else if (ch == '\'') { stringBuilder.append("\\\'"); } - else if (ch == '\\' && charArr[i+1] == '\"') { + else if (ch == '\\' && charArr[i+1] == '\"' && !(i+2 == charArr.length)) { skipNext = true; stringBuilder.append(charArr[i+1]); } @@ -119,7 +119,7 @@ public class PyQuotedStringIntention extends BaseIntentionAction { else if (ch == '"') { stringBuilder.append("\\\""); } - else if (ch == '\\' && charArr[i+1] == '\'') { + else if (ch == '\\' && charArr[i+1] == '\'' && !(i+2 == charArr.length)) { skipNext = true; stringBuilder.append(charArr[i+1]); } diff --git a/python/testData/intentions/afterQuotedStringDoubleSlash.py b/python/testData/intentions/afterQuotedStringDoubleSlash.py new file mode 100644 index 000000000000..64799d5c6f6b --- /dev/null +++ b/python/testData/intentions/afterQuotedStringDoubleSlash.py @@ -0,0 +1 @@ +data_path = dirname(realpath(__file__)).replace("\\", '/') \ No newline at end of file diff --git a/python/testData/intentions/beforeQuotedStringDoubleSlash.py b/python/testData/intentions/beforeQuotedStringDoubleSlash.py new file mode 100644 index 000000000000..b6bc075cbb51 --- /dev/null +++ b/python/testData/intentions/beforeQuotedStringDoubleSlash.py @@ -0,0 +1 @@ +data_path = dirname(realpath(__file__)).replace('\\', '/') \ 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 30a6fcd00d42..6a21242632eb 100644 --- a/python/testSrc/com/jetbrains/python/PyIntentionTest.java +++ b/python/testSrc/com/jetbrains/python/PyIntentionTest.java @@ -149,6 +149,10 @@ public class PyIntentionTest extends PyLightFixtureTestCase { doTest(PyBundle.message("INTN.quoted.string.double.to.single")); } + public void testQuotedStringDoubleSlash() { //PY-3295 + doTest(PyBundle.message("INTN.quoted.string.single.to.double")); + } + public void testEscapedQuotedString() { //PY-2656 doTest(PyBundle.message("INTN.quoted.string.single.to.double")); }