Fix for unicode escapes: use getText() instead of getStringValue()

This commit is contained in:
Valentina Kiryushkina
2017-05-05 12:59:07 +03:00
parent 9da8968a96
commit f1d8ea5c82
4 changed files with 9 additions and 2 deletions

View File

@@ -67,7 +67,7 @@ public class PyAddSpecifierToFormatQuickFix implements LocalQuickFix {
final PyExpression leftExpression = expression.getLeftExpression();
if (leftExpression instanceof PyStringLiteralExpression) {
final List<PyStringFormatParser.SubstitutionChunk> chunks =
filterSubstitutions(parsePercentFormat(((PyStringLiteralExpression)leftExpression).getStringValue()));
filterSubstitutions(parsePercentFormat(leftExpression.getText()));
PyExpression[] elements;
if (rightExpression instanceof PyTupleExpression) {
elements = ((PyTupleExpression)rightExpression).getElements();
@@ -76,7 +76,7 @@ public class PyAddSpecifierToFormatQuickFix implements LocalQuickFix {
elements = new PyExpression[]{rightExpression};
}
int shift = 2;
int shift = 1;
for (int i = 0; i < chunks.size(); i++) {
final PyStringFormatParser.PercentSubstitutionChunk chunk = PyUtil.as(chunks.get(i), PyStringFormatParser.PercentSubstitutionChunk.class);
if (chunk != null) {

View File

@@ -0,0 +1,2 @@
s = <warning descr="Format specifier character missing">u"\N{LATIN SMALL LETTER B}%s\N{NUMBER SIGN}\
%\N{LATIN SMALL <caret>LETTER B}"</warning> % ("a", "b")

View File

@@ -0,0 +1,2 @@
s = u"\N{LATIN SMALL LETTER B}%s\N{NUMBER SIGN}\
%s\N{LATIN SMALL LETTER B}" % ("a", "b")

View File

@@ -43,4 +43,7 @@ public class PyAddSpecifierToFormatQuickFixTest extends PyQuickFixTestCase {
doQuickFixTest(PyStringFormatInspection.class, PyBundle.message("QFIX.NAME.add.specifier"));
}
public void testUnicodeEscapes() {
doQuickFixTest(PyStringFormatInspection.class, PyBundle.message("QFIX.NAME.add.specifier"));
}
}