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
01b3a08f
Commit
01b3a08f
authored
Jan 25, 2013
by
Serhiy Storchaka
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Issue #16975: Fix error handling bug in the escape-decode decoder.
parent
1c60c7ac
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
50 additions
and
0 deletions
+50
-0
Lib/test/test_codecs.py
Lib/test/test_codecs.py
+44
-0
Misc/NEWS
Misc/NEWS
+2
-0
Objects/stringobject.c
Objects/stringobject.c
+4
-0
No files found.
Lib/test/test_codecs.py
View file @
01b3a08f
...
...
@@ -730,6 +730,50 @@ class EscapeDecodeTest(unittest.TestCase):
def
test_empty
(
self
):
self
.
assertEqual
(
codecs
.
escape_decode
(
""
),
(
""
,
0
))
def
test_raw
(
self
):
for
b
in
''
.
join
(
map
(
chr
,
range
(
256
))):
if
b
!=
'
\
\
'
:
self
.
assertEqual
(
codecs
.
escape_decode
(
b
+
'0'
),
(
b
+
'0'
,
2
))
def
test_escape
(
self
):
self
.
assertEqual
(
codecs
.
escape_decode
(
b"[
\
\
\
n
]"
),
(
b"[]"
,
4
))
self
.
assertEqual
(
codecs
.
escape_decode
(
br'[\"]'
),
(
b'["]'
,
4
))
self
.
assertEqual
(
codecs
.
escape_decode
(
br"[\']"
),
(
b"[']"
,
4
))
self
.
assertEqual
(
codecs
.
escape_decode
(
br"[\\]"
),
(
br"[\
]
", 4))
self.assertEqual(codecs.escape_decode(br"
[
\
a
]
"), (b"
[
\
x07
]
", 4))
self.assertEqual(codecs.escape_decode(br"
[
\
b
]
"), (b"
[
\
x08
]
", 4))
self.assertEqual(codecs.escape_decode(br"
[
\
t
]
"), (b"
[
\
x09
]
", 4))
self.assertEqual(codecs.escape_decode(br"
[
\
n
]
"), (b"
[
\
x0a
]
", 4))
self.assertEqual(codecs.escape_decode(br"
[
\
v
]
"), (b"
[
\
x0b
]
", 4))
self.assertEqual(codecs.escape_decode(br"
[
\
f
]
"), (b"
[
\
x0c
]
", 4))
self.assertEqual(codecs.escape_decode(br"
[
\
r
]
"), (b"
[
\
x0d
]
", 4))
self.assertEqual(codecs.escape_decode(br"
[
\
7
]
"), (b"
[
\
x07
]
", 4))
self.assertEqual(codecs.escape_decode(br"
[
\
8
]
"), (br"
[
\
8
]
", 4))
self.assertEqual(codecs.escape_decode(br"
[
\
78
]
"), (b"
[
\
x078
]
", 5))
self.assertEqual(codecs.escape_decode(br"
[
\
41
]
"), (b"
[
!
]
", 5))
self.assertEqual(codecs.escape_decode(br"
[
\
418
]
"), (b"
[
!
8
]
", 6))
self.assertEqual(codecs.escape_decode(br"
[
\
101
]
"), (b"
[
A
]
", 6))
self.assertEqual(codecs.escape_decode(br"
[
\
1010
]
"), (b"
[
A0
]
", 7))
self.assertEqual(codecs.escape_decode(br"
[
\
501
]
"), (b"
[
A
]
", 6))
self.assertEqual(codecs.escape_decode(br"
[
\
x41
]
"), (b"
[
A
]
", 6))
self.assertEqual(codecs.escape_decode(br"
[
\
X41
]
"), (br"
[
\
X41
]
", 6))
self.assertEqual(codecs.escape_decode(br"
[
\
x410
]
"), (b"
[
A0
]
", 7))
for b in ''.join(map(chr, range(256))):
if b not in '
\
n
"
\
'
\
\
abtnvfr01234567x'
:
self
.
assertEqual
(
codecs
.
escape_decode
(
'
\
\
'
+
b
),
(
'
\
\
'
+
b
,
2
))
def
test_errors
(
self
):
self
.
assertRaises
(
ValueError
,
codecs
.
escape_decode
,
br"\
x
")
self.assertRaises(ValueError, codecs.escape_decode, br"
[
\
x
]
")
self.assertEqual(codecs.escape_decode(br"
[
\
x
]
\
x
", "
ignore
"), (b"
[]
", 6))
self.assertEqual(codecs.escape_decode(br"
[
\
x
]
\
x
", "
replace
"), (b"
[
?
]
?
", 6))
self.assertRaises(ValueError, codecs.escape_decode, br"
\
x0
")
self.assertRaises(ValueError, codecs.escape_decode, br"
[
\
x0
]
")
self.assertEqual(codecs.escape_decode(br"
[
\
x0
]
\
x0
", "
ignore
"), (b"
[]
", 8))
self.assertEqual(codecs.escape_decode(br"
[
\
x0
]
\
x0
", "
replace
"), (b"
[
?
]
?
", 8))
class RecodingTest(unittest.TestCase):
def test_recoding(self):
f = StringIO.StringIO()
...
...
Misc/NEWS
View file @
01b3a08f
...
...
@@ -9,6 +9,8 @@ What's New in Python 2.7.4
Core and Builtins
-----------------
- Issue #16975: Fix error handling bug in the escape-decode decoder.
- Issue #14850: Now a charmap decoder treats U+FFFE as "undefined mapping"
in any mapping, not only in a Unicode string.
...
...
Objects/stringobject.c
View file @
01b3a08f
...
...
@@ -726,6 +726,10 @@ PyObject *PyString_DecodeEscape(const char *s,
errors
);
goto
failed
;
}
/* skip \x */
if
(
s
<
end
&&
isxdigit
(
Py_CHARMASK
(
s
[
0
])))
s
++
;
/* and a hexdigit */
break
;
#ifndef Py_USING_UNICODE
case
'u'
:
case
'U'
:
...
...
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