PY-21161 Check that index fragment of .format() string doesn't contain backslash

This commit is contained in:
Mikhail Golubev
2016-10-25 21:30:13 +03:00
parent 7f476d1302
commit c5f8bf51d5
4 changed files with 9 additions and 0 deletions
@@ -360,6 +360,9 @@ public class PyConvertToFStringIntention extends PyBaseIntentionAction {
escaped.add(part);
}
else if (part.startsWith("[")) {
if (part.contains("\\")) {
return null;
}
final String indexText = part.substring(1, part.length() - 1);
if (indexText.matches("\\d+")) {
escaped.add(part);
@@ -0,0 +1 @@
'{0[\\]}'.format(undefined)
@@ -0,0 +1 @@
'{0[\\]}'.format(undefined)
@@ -99,6 +99,10 @@ public class PyConvertToFStringIntentionTest extends PyIntentionTestCase {
public void testFormatMethodIndexContainsHostAlternativeQuote() {
doTest();
}
public void testFormatMethodIndexContainsBackslash() {
doTest();
}
public void testPercentOperatorWidthAndPrecision() {
doTest();