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
c9ad8b7a
Commit
c9ad8b7a
authored
Dec 28, 2016
by
Serhiy Storchaka
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Issue #29073: bytearray formatting no longer truncates on first null byte.
parent
af9181a4
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
12 additions
and
1 deletion
+12
-1
Lib/test/test_format.py
Lib/test/test_format.py
+7
-0
Misc/NEWS
Misc/NEWS
+2
-0
Objects/bytearrayobject.c
Objects/bytearrayobject.c
+3
-1
No files found.
Lib/test/test_format.py
View file @
c9ad8b7a
...
...
@@ -388,6 +388,13 @@ class FormatTest(unittest.TestCase):
else
:
raise
TestFailed
(
'"%*d"%(maxsize, -127) should fail'
)
def
test_nul
(
self
):
# test the null character
testcommon
(
"a
\
0
b"
,
(),
'a
\
0
b'
)
testcommon
(
"a%cb"
,
(
0
,),
'a
\
0
b'
)
testformat
(
"a%sb"
,
(
'c
\
0
d'
,),
'ac
\
0
db'
)
testcommon
(
b"a%sb"
,
(
b'c
\
0
d'
,),
b'ac
\
0
db'
)
def
test_non_ascii
(
self
):
testformat
(
"
\
u20ac
=%f"
,
(
1.0
,),
"
\
u20ac
=1.000000"
)
...
...
Misc/NEWS
View file @
c9ad8b7a
...
...
@@ -10,6 +10,8 @@ Release date: TBA
Core and Builtins
-----------------
- Issue #29073: bytearray formatting no longer truncates on first null byte.
- Issue #28932: Do not include <sys/random.h> if it does not exist.
- Issue #28147: Fix a memory leak in split-table dictionaries: setattr()
...
...
Objects/bytearrayobject.c
View file @
c9ad8b7a
...
...
@@ -283,13 +283,15 @@ bytearray_format(PyByteArrayObject *self, PyObject *args)
{
PyObject
*
bytes_in
,
*
bytes_out
,
*
res
;
char
*
bytestring
;
Py_ssize_t
bytesize
;
if
(
self
==
NULL
||
!
PyByteArray_Check
(
self
)
||
args
==
NULL
)
{
PyErr_BadInternalCall
();
return
NULL
;
}
bytestring
=
PyByteArray_AS_STRING
(
self
);
bytes_in
=
PyBytes_FromString
(
bytestring
);
bytesize
=
PyByteArray_GET_SIZE
(
self
);
bytes_in
=
PyBytes_FromStringAndSize
(
bytestring
,
bytesize
);
if
(
bytes_in
==
NULL
)
return
NULL
;
bytes_out
=
_PyBytes_Format
(
bytes_in
,
args
);
...
...
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