Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cpython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
cpython
Commits
9b88fdf4
Commit
9b88fdf4
authored
8 years ago
by
Eric V. Smith
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fixed issue #28633: segfault when concatenating bytes literal and f-string.
parent
f46b7823
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
12 additions
and
4 deletions
+12
-4
Lib/test/test_fstring.py
Lib/test/test_fstring.py
+7
-0
Python/ast.c
Python/ast.c
+5
-4
No files found.
Lib/test/test_fstring.py
View file @
9b88fdf4
...
...
@@ -92,6 +92,13 @@ f'{a * x()}'"""
exec
(
c
)
self
.
assertEqual
(
x
[
0
],
'foo3'
)
def
test_compile_time_concat_errors
(
self
):
self
.
assertAllRaise
(
SyntaxError
,
'cannot mix bytes and nonbytes literals'
,
[
r"""f'' b''"""
,
r"""b'' f''"""
,
])
def
test_literal
(
self
):
self
.
assertEqual
(
f''
,
''
)
self
.
assertEqual
(
f'a'
,
'a'
)
...
...
This diff is collapsed.
Click to expand it.
Python/ast.c
View file @
9b88fdf4
...
...
@@ -5147,7 +5147,8 @@ parsestrplus(struct compiling *c, const node *n)
/* Check that we're not mixing bytes with unicode. */
if
(
i
!=
0
&&
bytesmode
!=
this_bytesmode
)
{
ast_error
(
c
,
n
,
"cannot mix bytes and nonbytes literals"
);
Py_DECREF
(
s
);
/* s is NULL if the current string part is an f-string. */
Py_XDECREF
(
s
);
goto
error
;
}
bytesmode
=
this_bytesmode
;
...
...
@@ -5161,11 +5162,12 @@ parsestrplus(struct compiling *c, const node *n)
if
(
result
<
0
)
goto
error
;
}
else
{
/* A string or byte string. */
assert
(
s
!=
NULL
&&
fstr
==
NULL
);
assert
(
bytesmode
?
PyBytes_CheckExact
(
s
)
:
PyUnicode_CheckExact
(
s
));
/* A string or byte string. */
assert
(
s
!=
NULL
&&
fstr
==
NULL
);
if
(
bytesmode
)
{
/* For bytes, concat as we go. */
if
(
i
==
0
)
{
...
...
@@ -5177,7 +5179,6 @@ parsestrplus(struct compiling *c, const node *n)
goto
error
;
}
}
else
{
assert
(
s
!=
NULL
&&
fstr
==
NULL
);
/* This is a regular string. Concatenate it. */
if
(
FstringParser_ConcatAndDel
(
&
state
,
s
)
<
0
)
goto
error
;
...
...
This diff is collapsed.
Click to expand it.
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment