8000 Fix handling of backslash escapes in format strings · kaizhi-singtown/python@987290e · GitHub
[go: up one dir, main page]

Skip to content

Commit 987290e

Browse files
committed
Fix handling of backslash escapes in format strings
FIX: Fix a bug that broke handling of escaped quotes in format strings. Closes codemirror/dev#1166
1 parent c91887e commit 987290e

File tree

2 files changed

+5
-4
lines changed

2 files changed

+5
-4
lines changed

src/tokens.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import {
1313
} from "./parser.terms.js"
1414

1515
const newline = 10, carriageReturn = 13, space = 32, tab = 9, hash = 35, parenOpen = 40, dot = 46,
16-
braceOpen = 123, singleQuote = 39, doubleQuote = 34
16+
braceOpen = 123, singleQuote = 39, doubleQuote = 34, backslash = 92
1717

1818
const bracketed = new Set([
1919
ParenthesizedExpression, TupleExpression, ComprehensionExpression, importList, ArgList, ParamList,
@@ -126,7 +126,7 @@ function formatString(quote, len, content, brace, end) {
126126
}
127127
break
128128
}
129-
} else if (input.next == "\\") {
129+
} else if (input.next == backslash) {
130130
input.advance()
131131
if (input.next >= 0) input.advance()
132132
} else if (input.next == quote && (len == 1 || input.peek(1) == quote && input.peek(2) == quote)) {

test/expression.txt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,8 @@ Script(ExpressionStatement(CallExpression(VariableName, ArgList(ContinuedString(
4545

4646
# Format strings
4747

48-
f'hello{22} abc {{ }} {d-1}'
49-
f"double {quoted !s}"
48+
f'hello{22} abc\' {{ }} {d-1}'
49+
f"double\" {quoted !s}"
5050
f"""big long format
5151
{string :foo}"""
5252
f'''well {{ \x }} {2 :{bar}}'''
@@ -206,6 +206,7 @@ Script(AssignStatement(VariableName, AssignOp, ConditionalExpression(Number, if,
206206
2 ** 3 ** 2
207207

208208
==>
209+
209210
Script(ExpressionStatement(BinaryExpression(
210211
Number,ArithOp("**"),
211212
BinaryExpression(Number,ArithOp("**"),Number))))

0 commit comments

Comments
 (0)
0