Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(30773)

Side by Side Diff: Lib/test/test_codecs.py

Issue 20538: Segfault in UTF-7 incremental decoder
Patch Set: Created 5 years, 7 months ago
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | Objects/unicodeobject.c » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 import codecs 1 import codecs
2 import contextlib 2 import contextlib
3 import io 3 import io
4 import locale 4 import locale
5 import sys 5 import sys
6 import unittest 6 import unittest
7 import warnings 7 import warnings
8 import encodings 8 import encodings
9 9
10 from test import support 10 from test import support
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after
117 self.assertEqual(d.decode(b"", True), "") 117 self.assertEqual(d.decode(b"", True), "")
118 self.assertEqual(d.buffer, b"") 118 self.assertEqual(d.buffer, b"")
119 119
120 # check iterdecode() 120 # check iterdecode()
121 encoded = input.encode(self.encoding) 121 encoded = input.encode(self.encoding)
122 self.assertEqual( 122 self.assertEqual(
123 input, 123 input,
124 "".join(codecs.iterdecode([bytes([c]) for c in encoded], self.encodi ng)) 124 "".join(codecs.iterdecode([bytes([c]) for c in encoded], self.encodi ng))
125 ) 125 )
126 126
127 # Temporary skip, see http://bugs.python.org/issue20542
128 @unittest.skip
129 def test_readline(self): 127 def test_readline(self):
130 def getreader(input): 128 def getreader(input):
131 stream = io.BytesIO(input.encode(self.encoding)) 129 stream = io.BytesIO(input.encode(self.encoding))
132 return codecs.getreader(self.encoding)(stream) 130 return codecs.getreader(self.encoding)(stream)
133 131
134 def readalllines(input, keepends=True, size=None): 132 def readalllines(input, keepends=True, size=None):
135 reader = getreader(input) 133 reader = getreader(input)
136 lines = [] 134 lines = []
137 while True: 135 while True:
138 line = reader.readline(size=size, keepends=keepends) 136 line = reader.readline(size=size, keepends=keepends)
(...skipping 753 matching lines...) Expand 10 before | Expand all | Expand 10 after
892 "\U00010fff\uD800") 890 "\U00010fff\uD800")
893 self.assertTrue(codecs.lookup_error("surrogatepass")) 891 self.assertTrue(codecs.lookup_error("surrogatepass"))
894 892
895 893
896 894
897 class UTF7Test(ReadTest, unittest.TestCase): 895 class UTF7Test(ReadTest, unittest.TestCase):
898 encoding = "utf-7" 896 encoding = "utf-7"
899 897
900 def test_partial(self): 898 def test_partial(self):
901 self.check_partial( 899 self.check_partial(
902 "a+-b", 900 'a+-b\x00c\x80d\u0100e\U00010000f',
903 [ 901 [
904 "a", 902 'a',
905 "a", 903 'a',
906 "a+", 904 'a+',
907 "a+-", 905 'a+-',
908 "a+-b", 906 'a+-b',
907 'a+-b',
908 'a+-b',
909 'a+-b',
910 'a+-b',
911 'a+-b\x00',
912 'a+-b\x00c',
913 'a+-b\x00c',
914 'a+-b\x00c',
915 'a+-b\x00c',
916 'a+-b\x00c',
917 'a+-b\x00c\x80',
918 'a+-b\x00c\x80d',
919 'a+-b\x00c\x80d',
920 'a+-b\x00c\x80d',
921 'a+-b\x00c\x80d',
922 'a+-b\x00c\x80d',
923 'a+-b\x00c\x80d\u0100',
924 'a+-b\x00c\x80d\u0100e',
925 'a+-b\x00c\x80d\u0100e',
926 'a+-b\x00c\x80d\u0100e',
927 'a+-b\x00c\x80d\u0100e',
928 'a+-b\x00c\x80d\u0100e',
929 'a+-b\x00c\x80d\u0100e',
930 'a+-b\x00c\x80d\u0100e',
931 'a+-b\x00c\x80d\u0100e',
932 'a+-b\x00c\x80d\u0100e\U00010000',
933 'a+-b\x00c\x80d\u0100e\U00010000f',
909 ] 934 ]
910 ) 935 )
911 936
912 def test_errors(self): 937 def test_errors(self):
913 tests = [ 938 tests = [
914 (b'a\xffb', 'a\ufffdb'), 939 (b'a\xffb', 'a\ufffdb'),
915 (b'a+IK', 'a\ufffd'), 940 (b'a+IK', 'a\ufffd'),
916 (b'a+IK-b', 'a\ufffdb'), 941 (b'a+IK-b', 'a\ufffdb'),
917 (b'a+IK,b', 'a\ufffdb'), 942 (b'a+IK,b', 'a\ufffdb'),
918 (b'a+IKx', 'a\u20ac\ufffd'), 943 (b'a+IKx', 'a\u20ac\ufffd'),
(...skipping 1931 matching lines...) Expand 10 before | Expand all | Expand 10 after
2850 self.assertEqual(decoded, ('\u9a3e\u9a3e', 4)) 2875 self.assertEqual(decoded, ('\u9a3e\u9a3e', 4))
2851 2876
2852 decoded = codecs.code_page_decode(932, 2877 decoded = codecs.code_page_decode(932,
2853 b'abc', 'strict', 2878 b'abc', 'strict',
2854 False) 2879 False)
2855 self.assertEqual(decoded, ('abc', 3)) 2880 self.assertEqual(decoded, ('abc', 3))
2856 2881
2857 2882
2858 if __name__ == "__main__": 2883 if __name__ == "__main__":
2859 unittest.main() 2884 unittest.main()
OLDNEW
« no previous file with comments | « no previous file | Objects/unicodeobject.c » ('j') | no next file with comments »

RSS Feeds Recent Issues | This issue
This is Rietveld 894c83f36cb7+