PY-24610 Exception because of Invalid TextRange in format string: use PyStringLiteralExpression#getText() instead of PyStringLiteralExpression#getStringValue()

This commit is contained in:
Valentina Kiryushkina
2017-06-07 19:58:25 +03:00
parent 45829836d6
commit 00d44b070b
4 changed files with 10 additions and 4 deletions
@@ -197,13 +197,13 @@ public class PyStringFormatCompletionContributor extends CompletionContributor {
@NotNull
private static List<LookupElement> getFormatLookupBuilders(@NotNull final PyStringLiteralExpression expression) {
final Map<String, PyStringFormatParser.SubstitutionChunk> chunks = PyStringFormatParser.getKeywordSubstitutions(
PyStringFormatParser.filterSubstitutions(PyStringFormatParser.parseNewStyleFormat(expression.getStringValue())));
PyStringFormatParser.filterSubstitutions(PyStringFormatParser.parseNewStyleFormat(expression.getText())));
return getLookupBuilders(chunks);
}
private static List<LookupElement> getPercentLookupBuilders(@NotNull final PyStringLiteralExpression expression) {
final Map<String, PyStringFormatParser.SubstitutionChunk> chunks = PyStringFormatParser.getKeywordSubstitutions(
PyStringFormatParser.filterSubstitutions(PyStringFormatParser.parsePercentFormat(expression.getStringValue())));
PyStringFormatParser.filterSubstitutions(PyStringFormatParser.parsePercentFormat(expression.getText())));
return getLookupBuilders(chunks);
}
@@ -346,7 +346,7 @@ public class PyStringFormatInspection extends PyInspection {
}
private void inspectPercentFormat(@NotNull final PyStringLiteralExpression formatExpression) {
final String value = formatExpression.getStringValue();
final String value = formatExpression.getText();
final List<PyStringFormatParser.SubstitutionChunk> chunks = filterSubstitutions(parsePercentFormat(value));
myExpectedArguments = chunks.size();
@@ -482,7 +482,7 @@ public class PyStringFormatInspection extends PyInspection {
}
public void inspect() {
final String value = myFormatExpression.getStringValue();
final String value = myFormatExpression.getText();
final List<PyStringFormatParser.SubstitutionChunk> chunks = filterSubstitutions(PyStringFormatParser.parseNewStyleFormat(value));
for (int i = 0; i < chunks.size(); i++) {
@@ -0,0 +1,2 @@
u"{key}".format(key=1)
<warning descr="Key 'k' has no corresponding argument">u"{k}"</warning>.format(key=1)
@@ -193,6 +193,10 @@ public class PyStringFormatInspectionTest extends PyTestCase {
doTest();
}
public void testEscapedString() {
doTest();
}
//PY-21166
public void testUnsupportedFormatSpecifierNewStyleFormatting() {
doTest();