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
047c05eb
Commit
047c05eb
authored
Mar 21, 2002
by
Martin v. Löwis
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Do not insert characters for unicode-escape decoders if the error mode
is "ignore". Fixes #529104.
parent
bdf1f19f
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
32 additions
and
14 deletions
+32
-14
Lib/test/test_unicode.py
Lib/test/test_unicode.py
+8
-0
Objects/unicodeobject.c
Objects/unicodeobject.c
+24
-14
No files found.
Lib/test/test_unicode.py
View file @
047c05eb
...
@@ -541,6 +541,14 @@ else:
...
@@ -541,6 +541,14 @@ else:
verify(unicode('
Andr
\
202
x
','
ascii
','
ignore
') == u"Andr x")
verify(unicode('
Andr
\
202
x
','
ascii
','
ignore
') == u"Andr x")
verify(unicode('
Andr
\
202
x
','
ascii
','
replace
') == u'
Andr
\
uFFFD
x
')
verify(unicode('
Andr
\
202
x
','
ascii
','
replace
') == u'
Andr
\
uFFFD
x
')
verify("
\
\
N{foo}xx".decode("unicode-escape", "ignore") == u"xx")
try:
"
\
\
".decode("unicode-escape")
except ValueError:
pass
else:
raise TestFailed, '"
\
\
"
.
decode
(
"unicode-escape"
)
should
fail
'
verify(u'
hello
'.encode('
ascii
') == '
hello
')
verify(u'
hello
'.encode('
ascii
') == '
hello
')
verify(u'
hello
'.encode('
utf
-
7
') == '
hello
')
verify(u'
hello
'.encode('
utf
-
7
') == '
hello
')
verify(u'
hello
'.encode('
utf
-
8
') == '
hello
')
verify(u'
hello
'.encode('
utf
-
8
') == '
hello
')
...
...
Objects/unicodeobject.c
View file @
047c05eb
...
@@ -1514,8 +1514,7 @@ PyObject *PyUnicode_AsUTF16String(PyObject *unicode)
...
@@ -1514,8 +1514,7 @@ PyObject *PyUnicode_AsUTF16String(PyObject *unicode)
/* --- Unicode Escape Codec ----------------------------------------------- */
/* --- Unicode Escape Codec ----------------------------------------------- */
static
static
int
unicodeescape_decoding_error
(
const
char
**
source
,
int
unicodeescape_decoding_error
(
Py_UNICODE
**
x
,
Py_UNICODE
*
x
,
const
char
*
errors
,
const
char
*
errors
,
const
char
*
details
)
const
char
*
details
)
{
{
...
@@ -1530,7 +1529,8 @@ int unicodeescape_decoding_error(const char **source,
...
@@ -1530,7 +1529,8 @@ int unicodeescape_decoding_error(const char **source,
return
0
;
return
0
;
}
}
else
if
(
strcmp
(
errors
,
"replace"
)
==
0
)
{
else
if
(
strcmp
(
errors
,
"replace"
)
==
0
)
{
*
x
=
Py_UNICODE_REPLACEMENT_CHARACTER
;
**
x
=
Py_UNICODE_REPLACEMENT_CHARACTER
;
(
*
x
)
++
;
return
0
;
return
0
;
}
}
else
{
else
{
...
@@ -1628,9 +1628,9 @@ PyObject *PyUnicode_DecodeUnicodeEscape(const char *s,
...
@@ -1628,9 +1628,9 @@ PyObject *PyUnicode_DecodeUnicodeEscape(const char *s,
for
(
i
=
0
;
i
<
digits
;
i
++
)
{
for
(
i
=
0
;
i
<
digits
;
i
++
)
{
c
=
(
unsigned
char
)
s
[
i
];
c
=
(
unsigned
char
)
s
[
i
];
if
(
!
isxdigit
(
c
))
{
if
(
!
isxdigit
(
c
))
{
if
(
unicodeescape_decoding_error
(
&
s
,
&
x
,
errors
,
message
))
if
(
unicodeescape_decoding_error
(
&
p
,
errors
,
message
))
goto
onError
;
goto
onError
;
chr
=
x
;
chr
=
0xffffffff
;
i
++
;
i
++
;
break
;
break
;
}
}
...
@@ -1643,6 +1643,10 @@ PyObject *PyUnicode_DecodeUnicodeEscape(const char *s,
...
@@ -1643,6 +1643,10 @@ PyObject *PyUnicode_DecodeUnicodeEscape(const char *s,
chr
+=
10
+
c
-
'A'
;
chr
+=
10
+
c
-
'A'
;
}
}
s
+=
i
;
s
+=
i
;
if
(
chr
==
0xffffffff
)
/* _decoding_error will have already written into the
target buffer. */
break
;
store:
store:
/* when we get here, chr is a 32-bit unicode character */
/* when we get here, chr is a 32-bit unicode character */
if
(
chr
<=
0xffff
)
if
(
chr
<=
0xffff
)
...
@@ -1660,11 +1664,10 @@ PyObject *PyUnicode_DecodeUnicodeEscape(const char *s,
...
@@ -1660,11 +1664,10 @@ PyObject *PyUnicode_DecodeUnicodeEscape(const char *s,
#endif
#endif
}
else
{
}
else
{
if
(
unicodeescape_decoding_error
(
if
(
unicodeescape_decoding_error
(
&
s
,
&
x
,
errors
,
&
p
,
errors
,
"illegal Unicode character"
)
"illegal Unicode character"
)
)
)
goto
onError
;
goto
onError
;
*
p
++
=
x
;
/* store replacement character */
}
}
break
;
break
;
...
@@ -1699,14 +1702,19 @@ PyObject *PyUnicode_DecodeUnicodeEscape(const char *s,
...
@@ -1699,14 +1702,19 @@ PyObject *PyUnicode_DecodeUnicodeEscape(const char *s,
goto
store
;
goto
store
;
}
}
}
}
if
(
unicodeescape_decoding_error
(
&
s
,
&
x
,
errors
,
message
))
if
(
unicodeescape_decoding_error
(
&
p
,
errors
,
message
))
goto
onError
;
goto
onError
;
*
p
++
=
x
;
break
;
break
;
default:
default:
*
p
++
=
'\\'
;
if
(
s
>
end
)
{
*
p
++
=
(
unsigned
char
)
s
[
-
1
];
if
(
unicodeescape_decoding_error
(
&
p
,
errors
,
"
\\
at end of string"
))
goto
onError
;
}
else
{
*
p
++
=
'\\'
;
*
p
++
=
(
unsigned
char
)
s
[
-
1
];
}
break
;
break
;
}
}
}
}
...
@@ -1909,7 +1917,7 @@ PyObject *PyUnicode_DecodeRawUnicodeEscape(const char *s,
...
@@ -1909,7 +1917,7 @@ PyObject *PyUnicode_DecodeRawUnicodeEscape(const char *s,
end
=
s
+
size
;
end
=
s
+
size
;
while
(
s
<
end
)
{
while
(
s
<
end
)
{
unsigned
char
c
;
unsigned
char
c
;
Py_U
NICODE
x
;
Py_U
CS4
x
;
int
i
;
int
i
;
/* Non-escape characters are interpreted as Unicode ordinals */
/* Non-escape characters are interpreted as Unicode ordinals */
...
@@ -1938,9 +1946,10 @@ PyObject *PyUnicode_DecodeRawUnicodeEscape(const char *s,
...
@@ -1938,9 +1946,10 @@ PyObject *PyUnicode_DecodeRawUnicodeEscape(const char *s,
for
(
x
=
0
,
i
=
0
;
i
<
4
;
i
++
)
{
for
(
x
=
0
,
i
=
0
;
i
<
4
;
i
++
)
{
c
=
(
unsigned
char
)
s
[
i
];
c
=
(
unsigned
char
)
s
[
i
];
if
(
!
isxdigit
(
c
))
{
if
(
!
isxdigit
(
c
))
{
if
(
unicodeescape_decoding_error
(
&
s
,
&
x
,
errors
,
if
(
unicodeescape_decoding_error
(
&
p
,
errors
,
"truncated
\\
uXXXX"
))
"truncated
\\
uXXXX"
))
goto
onError
;
goto
onError
;
x
=
0xffffffff
;
i
++
;
i
++
;
break
;
break
;
}
}
...
@@ -1953,7 +1962,8 @@ PyObject *PyUnicode_DecodeRawUnicodeEscape(const char *s,
...
@@ -1953,7 +1962,8 @@ PyObject *PyUnicode_DecodeRawUnicodeEscape(const char *s,
x
+=
10
+
c
-
'A'
;
x
+=
10
+
c
-
'A'
;
}
}
s
+=
i
;
s
+=
i
;
*
p
++
=
x
;
if
(
x
!=
0xffffffff
)
*
p
++
=
x
;
}
}
if
(
_PyUnicode_Resize
(
&
v
,
(
int
)(
p
-
buf
)))
if
(
_PyUnicode_Resize
(
&
v
,
(
int
)(
p
-
buf
)))
goto
onError
;
goto
onError
;
...
...
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