mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
fixed PY-2915 Convert double-quoted string to single-quoted string: breaks code in case of escaped characters
This commit is contained in:
@@ -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]);
|
||||
}
|
||||
|
||||
@@ -1 +1 @@
|
||||
a = '\'Hello\' - said man.'
|
||||
a = '\'Hello\' - said man.\n Let\'s go.'
|
||||
@@ -1 +1 @@
|
||||
a = "'Hello'<caret> - said man."
|
||||
a = "'Hello'<caret> - said man.\n Let's go."
|
||||
@@ -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"));
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user