@@ -363,8 +363,8 @@ def test(self):
363363
364364
365365# TODO: Remove when dropping support for PY37. Backport of unit tests for
366- # urllib.parse.parse_qsl() from Python 3.8. Copyright (C) 2020 Python Software
367- # Foundation (see LICENSE.python).
366+ # urllib.parse.parse_qsl() from Python 3.8.8. Copyright (C) 2021 Python
367+ # Software Foundation (see LICENSE.python).
368368class ParseQSLBackportTests (unittest .TestCase ):
369369 def test_parse_qsl (self ):
370370 tests = [
@@ -388,16 +388,10 @@ def test_parse_qsl(self):
388388 (b'&a=b' , [(b'a' , b'b' )]),
389389 (b'a=a+b&b=b+c' , [(b'a' , b'a b' ), (b'b' , b'b c' )]),
390390 (b'a=1&a=2' , [(b'a' , b'1' ), (b'a' , b'2' )]),
391- (';' , []),
392- (';;' , []),
393- (';a=b' , [('a' , 'b' )]),
394- ('a=a+b;b=b+c' , [('a' , 'a b' ), ('b' , 'b c' )]),
395- ('a=1;a=2' , [('a' , '1' ), ('a' , '2' )]),
396- (b';' , []),
397- (b';;' , []),
398- (b';a=b' , [(b'a' , b'b' )]),
399- (b'a=a+b;b=b+c' , [(b'a' , b'a b' ), (b'b' , b'b c' )]),
400- (b'a=1;a=2' , [(b'a' , b'1' ), (b'a' , b'2' )]),
391+ (';a=b' , [(';a' , 'b' )]),
392+ ('a=a+b;b=b+c' , [('a' , 'a b;b=b c' )]),
393+ (b';a=b' , [(b';a' , b'b' )]),
394+ (b'a=a+b;b=b+c' , [(b'a' , b'a b;b=b c' )]),
401395 ]
402396 for original , expected in tests :
403397 with self .subTest (original ):
@@ -422,6 +416,27 @@ def test_parse_qsl_encoding(self):
422416 def test_parse_qsl_max_num_fields (self ):
423417 with self .assertRaises (ValueError ):
424418 parse_qsl ('&' .join (['a=a' ] * 11 ), max_num_fields = 10 )
425- with self .assertRaises (ValueError ):
426- parse_qsl (';' .join (['a=a' ] * 11 ), max_num_fields = 10 )
427419 parse_qsl ('&' .join (['a=a' ] * 10 ), max_num_fields = 10 )
420+
421+ def test_parse_qsl_separator (self ):
422+ tests = [
423+ (';' , []),
424+ (';;' , []),
425+ ('=;a' , []),
426+ (';a=b' , [('a' , 'b' )]),
427+ ('a=a+b;b=b+c' , [('a' , 'a b' ), ('b' , 'b c' )]),
428+ ('a=1;a=2' , [('a' , '1' ), ('a' , '2' )]),
429+ (b';' , []),
430+ (b';;' , []),
431+ (b';a=b' , [(b'a' , b'b' )]),
432+ (b'a=a+b;b=b+c' , [(b'a' , b'a b' ), (b'b' , b'b c' )]),
433+ (b'a=1;a=2' , [(b'a' , b'1' ), (b'a' , b'2' )]),
434+ ]
435+ for original , expected in tests :
436+ with self .subTest (original ):
437+ result = parse_qsl (original , separator = ';' )
438+ self .assertEqual (result , expected , 'Error parsing %r' % original )
439+
440+ def test_parse_qsl_bad_separator (self ):
441+ with self .assertRaisesRegex (ValueError , 'Separator must be of type string or bytes.' ):
442+ parse_qsl ('a=b0c=d' , separator = 0 )
0 commit comments