Skip to content
Projeler
Gruplar
Parçacıklar
Yardım
Yükleniyor...
Oturum aç / Kaydol
Gezinmeyi değiştir
C
cpython
Proje
Proje
Ayrıntılar
Etkinlik
Cycle Analytics
Depo (repository)
Depo (repository)
Dosyalar
Kayıtlar (commit)
Dallar (branch)
Etiketler
Katkıda bulunanlar
Grafik
Karşılaştır
Grafikler
Konular (issue)
0
Konular (issue)
0
Liste
Pano
Etiketler
Kilometre Taşları
Birleştirme (merge) Talepleri
0
Birleştirme (merge) Talepleri
0
CI / CD
CI / CD
İş akışları (pipeline)
İşler
Zamanlamalar
Grafikler
Paketler
Paketler
Wiki
Wiki
Parçacıklar
Parçacıklar
Üyeler
Üyeler
Collapse sidebar
Close sidebar
Etkinlik
Grafik
Grafikler
Yeni bir konu (issue) oluştur
İşler
Kayıtlar (commit)
Konu (issue) Panoları
Kenar çubuğunu aç
Batuhan Osman TASKAYA
cpython
Commits
4fb8caee
Kaydet (Commit)
4fb8caee
authored
Ock 15, 2013
tarafından
Serhiy Storchaka
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Issue #14850: Now a chamap decoder treates U+FFFE as "undefined mapping"
in any mapping, not only in an unicode string.
üst
ad1d5f90
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
74 additions
and
21 deletions
+74
-21
test_codecs.py
Lib/test/test_codecs.py
+46
-0
NEWS
Misc/NEWS
+3
-0
unicodeobject.c
Objects/unicodeobject.c
+25
-21
No files found.
Lib/test/test_codecs.py
Dosyayı görüntüle @
4fb8caee
...
...
@@ -1586,6 +1586,10 @@ class CharmapTest(unittest.TestCase):
codecs
.
charmap_decode
,
b
"
\x00\x01\x02
"
,
"strict"
,
"ab"
)
self
.
assertRaises
(
UnicodeDecodeError
,
codecs
.
charmap_decode
,
b
"
\x00\x01\x02
"
,
"strict"
,
"ab
\ufffe
"
)
self
.
assertEqual
(
codecs
.
charmap_decode
(
b
"
\x00\x01\x02
"
,
"replace"
,
"ab"
),
(
"ab
\ufffd
"
,
3
)
...
...
@@ -1642,6 +1646,17 @@ class CharmapTest(unittest.TestCase):
{
0
:
'a'
,
1
:
'b'
}
)
self
.
assertRaises
(
UnicodeDecodeError
,
codecs
.
charmap_decode
,
b
"
\x00\x01\x02
"
,
"strict"
,
{
0
:
'a'
,
1
:
'b'
,
2
:
None
}
)
# Issue #14850
self
.
assertRaises
(
UnicodeDecodeError
,
codecs
.
charmap_decode
,
b
"
\x00\x01\x02
"
,
"strict"
,
{
0
:
'a'
,
1
:
'b'
,
2
:
'
\ufffe
'
}
)
self
.
assertEqual
(
codecs
.
charmap_decode
(
b
"
\x00\x01\x02
"
,
"replace"
,
{
0
:
'a'
,
1
:
'b'
}),
...
...
@@ -1654,6 +1669,13 @@ class CharmapTest(unittest.TestCase):
(
"ab
\ufffd
"
,
3
)
)
# Issue #14850
self
.
assertEqual
(
codecs
.
charmap_decode
(
b
"
\x00\x01\x02
"
,
"replace"
,
{
0
:
'a'
,
1
:
'b'
,
2
:
'
\ufffe
'
}),
(
"ab
\ufffd
"
,
3
)
)
self
.
assertEqual
(
codecs
.
charmap_decode
(
b
"
\x00\x01\x02
"
,
"ignore"
,
{
0
:
'a'
,
1
:
'b'
}),
...
...
@@ -1666,6 +1688,13 @@ class CharmapTest(unittest.TestCase):
(
"ab"
,
3
)
)
# Issue #14850
self
.
assertEqual
(
codecs
.
charmap_decode
(
b
"
\x00\x01\x02
"
,
"ignore"
,
{
0
:
'a'
,
1
:
'b'
,
2
:
'
\ufffe
'
}),
(
"ab"
,
3
)
)
allbytes
=
bytes
(
range
(
256
))
self
.
assertEqual
(
codecs
.
charmap_decode
(
allbytes
,
"ignore"
,
{}),
...
...
@@ -1700,18 +1729,35 @@ class CharmapTest(unittest.TestCase):
{
0
:
a
,
1
:
b
},
)
self
.
assertRaises
(
UnicodeDecodeError
,
codecs
.
charmap_decode
,
b
"
\x00\x01\x02
"
,
"strict"
,
{
0
:
a
,
1
:
b
,
2
:
0xFFFE
},
)
self
.
assertEqual
(
codecs
.
charmap_decode
(
b
"
\x00\x01\x02
"
,
"replace"
,
{
0
:
a
,
1
:
b
}),
(
"ab
\ufffd
"
,
3
)
)
self
.
assertEqual
(
codecs
.
charmap_decode
(
b
"
\x00\x01\x02
"
,
"replace"
,
{
0
:
a
,
1
:
b
,
2
:
0xFFFE
}),
(
"ab
\ufffd
"
,
3
)
)
self
.
assertEqual
(
codecs
.
charmap_decode
(
b
"
\x00\x01\x02
"
,
"ignore"
,
{
0
:
a
,
1
:
b
}),
(
"ab"
,
3
)
)
self
.
assertEqual
(
codecs
.
charmap_decode
(
b
"
\x00\x01\x02
"
,
"ignore"
,
{
0
:
a
,
1
:
b
,
2
:
0xFFFE
}),
(
"ab"
,
3
)
)
class
WithStmtTest
(
unittest
.
TestCase
):
def
test_encodedfile
(
self
):
...
...
Misc/NEWS
Dosyayı görüntüle @
4fb8caee
...
...
@@ -10,6 +10,9 @@ What's New in Python 3.2.4
Core and Builtins
-----------------
- Issue #14850: Now a chamap decoder treates U+FFFE as "undefined mapping"
in any mapping, not only in a string.
- Issue #11461: Fix the incremental UTF-16 decoder. Original patch by
Amaury Forgeot d'Arc.
...
...
Objects/unicodeobject.c
Dosyayı görüntüle @
4fb8caee
...
...
@@ -5245,15 +5245,18 @@ PyObject *PyUnicode_DecodeCharmap(const char *s,
if
(
PyErr_ExceptionMatches
(
PyExc_LookupError
))
{
/* No mapping found means: mapping is undefined. */
PyErr_Clear
();
x
=
Py_None
;
Py_INCREF
(
x
);
goto
Undefined
;
}
else
goto
onError
;
}
/* Apply mapping */
if
(
x
==
Py_None
)
goto
Undefined
;
if
(
PyLong_Check
(
x
))
{
long
value
=
PyLong_AS_LONG
(
x
);
if
(
value
==
0xFFFE
)
goto
Undefined
;
if
(
value
<
0
||
value
>
0x10FFFF
)
{
PyErr_SetString
(
PyExc_TypeError
,
"character mapping must be in range(0x110000)"
);
...
...
@@ -5286,29 +5289,16 @@ PyObject *PyUnicode_DecodeCharmap(const char *s,
#endif
*
p
++
=
(
Py_UNICODE
)
value
;
}
else
if
(
x
==
Py_None
)
{
/* undefined mapping */
outpos
=
p
-
PyUnicode_AS_UNICODE
(
v
);
startinpos
=
s
-
starts
;
endinpos
=
startinpos
+
1
;
if
(
unicode_decode_call_errorhandler
(
errors
,
&
errorHandler
,
"charmap"
,
"character maps to <undefined>"
,
&
starts
,
&
e
,
&
startinpos
,
&
endinpos
,
&
exc
,
&
s
,
&
v
,
&
outpos
,
&
p
))
{
Py_DECREF
(
x
);
goto
onError
;
}
Py_DECREF
(
x
);
continue
;
}
else
if
(
PyUnicode_Check
(
x
))
{
Py_ssize_t
targetsize
=
PyUnicode_GET_SIZE
(
x
);
if
(
targetsize
==
1
)
if
(
targetsize
==
1
)
{
/* 1-1 mapping */
*
p
++
=
*
PyUnicode_AS_UNICODE
(
x
);
Py_UNICODE
value
=
*
PyUnicode_AS_UNICODE
(
x
);
if
(
value
==
0xFFFE
)
goto
Undefined
;
*
p
++
=
value
;
}
else
if
(
targetsize
>
1
)
{
/* 1-n mapping */
if
(
targetsize
>
extrachars
)
{
...
...
@@ -5342,6 +5332,20 @@ PyObject *PyUnicode_DecodeCharmap(const char *s,
}
Py_DECREF
(
x
);
++
s
;
continue
;
Undefined:
/* undefined mapping */
Py_XDECREF
(
x
);
outpos
=
p
-
PyUnicode_AS_UNICODE
(
v
);
startinpos
=
s
-
starts
;
endinpos
=
startinpos
+
1
;
if
(
unicode_decode_call_errorhandler
(
errors
,
&
errorHandler
,
"charmap"
,
"character maps to <undefined>"
,
&
starts
,
&
e
,
&
startinpos
,
&
endinpos
,
&
exc
,
&
s
,
&
v
,
&
outpos
,
&
p
))
{
goto
onError
;
}
}
}
if
(
p
-
PyUnicode_AS_UNICODE
(
v
)
<
PyUnicode_GET_SIZE
(
v
))
...
...
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