File tree Expand file tree Collapse file tree 2 files changed +14
-1
lines changed Expand file tree Collapse file tree 2 files changed +14
-1
lines changed Original file line number Diff line number Diff line change @@ -530,8 +530,11 @@ def __new__(cls, value: Any) -> "TextStringObject":
530
530
o .autodetect_pdfdocencoding = False
531
531
o .utf16_bom = b""
532
532
if value .startswith (("\xfe \xff " , "\xff \xfe " )):
533
+ assert org is not None # for mypy
534
+ o = str .__new__ (cls , org .decode ("utf-16" ))
535
+ o ._original_bytes = org
533
536
o .autodetect_utf16 = True
534
- o .utf16_bom = value [:2 ]. encode ( "charmap" )
537
+ o .utf16_bom = org [:2 ]
535
538
else :
536
539
try :
537
540
encode_pdfdocencoding (o )
Original file line number Diff line number Diff line change @@ -1131,6 +1131,16 @@ def test_create_string_object_utf16_bom():
1131
1131
result .get_encoded_bytes ()
1132
1132
== b"\xff \xfe P\x00 a\x00 p\x00 e\x00 r\x00 P\x00 o\x00 r\x00 t\x00 \x00 1\x00 4\x00 \x00 \x00 "
1133
1133
)
1134
+ result = TextStringObject (
1135
+ b"\xff \xfe P\x00 a\x00 p\x00 e\x00 r\x00 P\x00 o\x00 r\x00 t\x00 \x00 1\x00 4\x00 \x00 \x00 "
1136
+ )
1137
+ assert result == "PaperPort 14\x00 "
1138
+ assert result .autodetect_utf16 is True
1139
+ assert result .utf16_bom == b"\xff \xfe "
1140
+ assert (
1141
+ result .get_encoded_bytes ()
1142
+ == b"\xff \xfe P\x00 a\x00 p\x00 e\x00 r\x00 P\x00 o\x00 r\x00 t\x00 \x00 1\x00 4\x00 \x00 \x00 "
1143
+ )
1134
1144
1135
1145
# utf16-be without bom
1136
1146
result = TextStringObject ("ÿ" )
You can’t perform that action at this time.
0 commit comments