fixed Convert triple-quoted string: loses data in case of double quote inside the string and leads to syntax error

This commit is contained in:
Ekaterina Tuzova
2013-01-16 16:12:55 +04:00
parent 519b7a9b74
commit df5ef4abf1
4 changed files with 12 additions and 9 deletions
@@ -95,16 +95,8 @@ public class PyConvertTripleQuotedStringIntention extends BaseIntentionAction {
subString = convertToValidSubString(trimmed.substring(0, trimmed.length() - 3), firstQuote);
}
else {
s = StringUtil.escapeStringCharacters(s);
StringBuilder stringBuilder = new StringBuilder();
for (Character ch : s.toCharArray()) {
if (ch == firstQuote) {
stringBuilder.append("\\").append(firstQuote);
}
else {
stringBuilder.append(ch);
}
}
stringBuilder = StringUtil.escapeStringCharacters(s.length(), s, String.valueOf(firstQuote), true, stringBuilder);
subString = stringBuilder.toString();
}
return subString;
@@ -0,0 +1,3 @@
s = ("\n"
"my quote\" some text after it\n"
)
@@ -0,0 +1,3 @@
s = """
my q<caret>uote" some text after it
"""
@@ -237,10 +237,15 @@ public class PyIntentionTest extends PyTestCase {
public void testConvertVariadicParam() { //PY-2264
doTest(PyBundle.message("INTN.convert.variadic.param"));
}
public void testConvertTripleQuotedString() { //PY-2697
doTest(PyBundle.message("INTN.triple.quoted.string"));
}
public void testConvertTripleQuotedString1() { //PY-7774
doTest(PyBundle.message("INTN.triple.quoted.string"));
}
public void testTransformConditionalExpression() { //PY-3094
doTest(PyBundle.message("INTN.transform.into.if.else.statement"));
}