@@ -746,6 +746,35 @@ def test_iter_attachments_mutation(self):
746
746
self .assertEqual (len (list (m .iter_attachments ())), 2 )
747
747
self .assertEqual (m .get_payload (), orig )
748
748
749
+ get_payload_surrogate_params = {
750
+
751
+ 'good_surrogateescape' : (
752
+ "String that can be encod\udcc3 \udcab d with surrogateescape" ,
753
+ b'String that can be encod\xc3 \xab d with surrogateescape'
754
+ ),
755
+
756
+ 'string_with_utf8' : (
757
+ "String with utf-8 charactër" ,
758
+ b'String with utf-8 charact\xeb r'
759
+ ),
760
+
761
+ 'surrogate_and_utf8' : (
762
+ "String that cannot be ëncod\udcc3 \udcab d with surrogateescape" ,
763
+ b'String that cannot be \xeb ncod\\ udcc3\\ udcabd with surrogateescape'
764
+ ),
765
+
766
+ 'out_of_range_surrogate' : (
767
+ "String with \udfff cannot be encoded with surrogateescape" ,
768
+ b'String with \\ udfff cannot be encoded with surrogateescape'
769
+ ),
770
+ }
771
+
772
+ def get_payload_surrogate_as_gh_94606 (self , msg , expected ):
773
+ """test for GH issue 94606"""
774
+ m = self ._str_msg (msg )
775
+ payload = m .get_payload (decode = True )
776
+ self .assertEqual (expected , payload )
777
+
749
778
750
779
class TestEmailMessage (TestEmailMessageBase , TestEmailBase ):
751
780
message = EmailMessage
@@ -954,42 +983,6 @@ def test_get_body_malformed(self):
954
983
# AttributeError: 'str' object has no attribute 'is_attachment'
955
984
m .get_body ()
956
985
957
- def test_get_payload_unicode_surrogate1 (self ):
958
- """test that fix for GH issue 94606 does not break this"""
959
- msg = "String that could have been decod\udcc3 \udcab d with surrogateescape"
960
- expected = b'String that could have been decod\xc3 \xab d with surrogateescape'
961
- m = self ._str_msg (msg )
962
- payload = m .get_payload (decode = True )
963
- self .assertEqual (expected , payload )
964
-
965
- def test_get_payload_unicode_surrogate2 (self ):
966
- """test that fix for GH issue 94606 does not break this"""
967
- msg = "Unicode string with a utf-8 charactër"
968
- expected = b'Unicode string with a utf-8 charact\xeb r'
969
- m = self ._str_msg (msg )
970
- payload = m .get_payload (decode = True )
971
- self .assertEqual (expected , payload )
972
-
973
- def test_get_payload_unicode_surrogate3 (self ):
974
- """test for GH issue 94606"""
975
- msg = "String that could not have been dëcod\udcc3 \udcab d with surrogateescape"
976
- expected = b'String that could not have been d\xeb cod\\ udcc3\udcabd with surrogateescape'
977
- m = self ._str_msg (msg )
978
- # In GH issue 94606, this would raise
979
- # UnicodeEncodeError: 'ascii' codec can't encode character '\xeb' in position 33: ordinal not in range(128)
980
- payload = m .get_payload (decode = True )
981
- self .assertEqual (expected , payload )
982
-
983
- def test_get_payload_unicode_surrogate4 (self ):
984
- """test for GH issue 94606"""
985
- msg = "Different reason \udfff could not have been decoded with surrogateescape"
986
- expected = b'Different reason \\ udfff could not have been decoded with surrogateescape'
987
- m = self ._str_msg (msg )
988
- # In GH issue 94606, this would raise
989
- # UnicodeEncodeError: 'ascii' codec can't encode character '\udfff' in position 17: ordinal not in range(128)
990
- payload = m .get_payload (decode = True )
991
- self .assertEqual (expected , payload )
992
-
993
986
994
987
class TestMIMEPart (TestEmailMessageBase , TestEmailBase ):
995
988
# Doing the full test run here may seem a bit redundant, since the two
0 commit comments