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
33798674
Commit
33798674
authored
Mar 01, 2016
by
Victor Stinner
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Issue #26464: Fix unicode_fast_translate() again
Initialize i variable if the string is non-ASCII.
parent
6c9aa8f2
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
22 additions
and
13 deletions
+22
-13
Lib/test/test_unicode.py
Lib/test/test_unicode.py
+10
-4
Objects/unicodeobject.c
Objects/unicodeobject.c
+12
-9
No files found.
Lib/test/test_unicode.py
View file @
33798674
...
...
@@ -341,16 +341,22 @@ class UnicodeTest(string_tests.CommonTest,
"[XXX]"
)
self
.
assertEqual
(
"[a]"
.
translate
(
str
.
maketrans
({
'a'
:
'
\
xe9
'
})),
"[
\
xe9
]"
)
self
.
assertEqual
(
'axb'
.
translate
(
str
.
maketrans
({
'a'
:
None
,
'b'
:
'123'
})),
"x123"
)
self
.
assertEqual
(
'axb'
.
translate
(
str
.
maketrans
({
'a'
:
None
,
'b'
:
'
\
xe9
'
})),
"x
\
xe9
"
)
# test non-ASCII (don't take the fast-path)
self
.
assertEqual
(
"[a]"
.
translate
(
str
.
maketrans
({
'a'
:
'<
\
xe9
>'
})),
"[<
\
xe9
>]"
)
self
.
assertEqual
(
"[
\
xe9
]"
.
translate
(
str
.
maketrans
({
'
\
xe9
'
:
'a'
})),
"[a]"
)
self
.
assertEqual
(
"[
\
xe9
]"
.
translate
(
str
.
maketrans
({
'
\
xe9
'
:
None
})),
"[]"
)
self
.
assertEqual
(
'axb'
.
translate
(
str
.
maketrans
({
'a'
:
None
,
'b
'
:
'123'
})),
"
x123
"
)
self
.
assertEqual
(
'axb'
.
translate
(
str
.
maketrans
({
'a'
:
None
,
'b'
:
'
\
xe9
'
})),
"
x
\
xe9
"
)
self
.
assertEqual
(
"[
\
xe9
]"
.
translate
(
str
.
maketrans
({
'
\
xe9
'
:
'123'
})),
"
[123]
"
)
self
.
assertEqual
(
"[a
\
xe9
]"
.
translate
(
str
.
maketrans
({
'a'
:
'<
\
u20ac
>
'
})),
"
[<
\
u20ac
>
\
xe9
]
"
)
# invalid Unicode characters
invalid_char
=
0x10ffff
+
1
...
...
Objects/unicodeobject.c
View file @
33798674
...
...
@@ -8582,10 +8582,6 @@ unicode_fast_translate(PyObject *input, PyObject *mapping,
Py_UCS1
*
in
,
*
end
,
*
out
;
int
res
=
0
;
if
(
PyUnicode_READY
(
input
)
==
-
1
)
return
-
1
;
if
(
!
PyUnicode_IS_ASCII
(
input
))
return
0
;
len
=
PyUnicode_GET_LENGTH
(
input
);
memset
(
ascii_table
,
0xff
,
128
);
...
...
@@ -8668,13 +8664,20 @@ _PyUnicode_TranslateCharmap(PyObject *input,
ignore
=
(
errors
!=
NULL
&&
strcmp
(
errors
,
"ignore"
)
==
0
);
res
=
unicode_fast_translate
(
input
,
mapping
,
&
writer
,
ignore
,
&
i
);
if
(
res
<
0
)
{
_PyUnicodeWriter_Dealloc
(
&
writer
);
if
(
PyUnicode_READY
(
input
)
==
-
1
)
return
NULL
;
if
(
PyUnicode_IS_ASCII
(
input
))
{
res
=
unicode_fast_translate
(
input
,
mapping
,
&
writer
,
ignore
,
&
i
);
if
(
res
<
0
)
{
_PyUnicodeWriter_Dealloc
(
&
writer
);
return
NULL
;
}
if
(
res
==
1
)
return
_PyUnicodeWriter_Finish
(
&
writer
);
}
else
{
i
=
0
;
}
if
(
res
==
1
)
return
_PyUnicodeWriter_Finish
(
&
writer
);
while
(
i
<
size
)
{
/* try to encode 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