Fixed braces escaping for new-style formatted strings (PY-8372)

This commit is contained in:
Andrey Vlasovskikh
2013-01-09 19:46:45 +04:00
parent 7230e05c77
commit 3e0784b9a9
2 changed files with 11 additions and 4 deletions
@@ -145,8 +145,8 @@ public class PyStringFormatParser {
final int n = s.length();
while (pos < n) {
int next = s.indexOf('{', pos);
while (next > 0 && s.charAt(next - 1) == '\\') {
next = s.indexOf('{', next + 1);
while (next > 0 && next < n - 1 && s.charAt(next + 1) == '{') {
next = s.indexOf('{', next + 2);
}
if (next < 0) {
break;
@@ -156,8 +156,8 @@ public class PyStringFormatParser {
}
pos = next;
next = s.indexOf('}', pos);
while (next > 0 && s.charAt(next - 1) == '\\') {
next = s.indexOf('}', next + 1);
while (next > 0 && next < n - 1 && s.charAt(next + 1) == '}') {
next = s.indexOf('}', next + 2);
}
if (next > pos) {
// TODO: Parse substitution details
@@ -119,4 +119,11 @@ public class PyStringFormatParserTest extends TestCase {
assertEquals(TextRange.create(1, 6), chunks.get(0).getTextRange());
assertEquals(TextRange.create(6, 11), chunks.get(1).getTextRange());
}
// PY-8372
public void testBracesEscaping() {
final List<SubstitutionChunk> chunks = filterSubstitutions(parseNewStyleFormat("\\{\\}, {{}}"));
assertEquals(1, chunks.size());
assertEquals(TextRange.create(1, 4), chunks.get(0).getTextRange());
}
}