Skip to content

Commit

Permalink
BUG: Fixed reference of value with str.__new__ in TextStringObject (#…
Browse files Browse the repository at this point in the history
…2952)

Closes #2949.

---------

Co-authored-by: Stefan <96178532+stefan6419846@users.noreply.github.com>
  • Loading branch information
thomas-forte and stefan6419846 authored Nov 29, 2024
1 parent 3d9464c commit a1d5de1
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 2 deletions.
2 changes: 1 addition & 1 deletion pypdf/_writer.py
Original file line number Diff line number Diff line change
Expand Up @@ -1049,7 +1049,7 @@ def _update_field_annotation(
def update_page_form_field_values(
self,
page: Union[PageObject, List[PageObject], None],
fields: Dict[str, Any],
fields: Dict[str, Union[str, List[str], Tuple[str, str, float]]],
flags: FA.FfBits = FFBITS_NUL,
auto_regenerate: Optional[bool] = True,
) -> None:
Expand Down
2 changes: 1 addition & 1 deletion pypdf/generic/_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -653,7 +653,7 @@ def __new__(cls, value: Any) -> "TextStringObject":
o.autodetect_utf16 = False
o.autodetect_pdfdocencoding = False
o.utf16_bom = b""
if value.startswith(("\xfe\xff", "\xff\xfe")):
if o.startswith(("\xfe\xff", "\xff\xfe")):
assert org is not None # for mypy
try:
o = str.__new__(cls, org.decode("utf-16"))
Expand Down
5 changes: 5 additions & 0 deletions tests/test_generic.py
Original file line number Diff line number Diff line change
Expand Up @@ -507,6 +507,11 @@ def test_textstringobject_autodetect_utf16():
assert tso.get_encoded_bytes() == b"\xff\xfef\x00o\x00o\x00"


def test_textstringobject__numbers_as_input():
_ = TextStringObject(42)
_ = TextStringObject(13.37)


def test_remove_child_not_in_tree():
tree = TreeObject()
with pytest.raises(ValueError) as exc:
Expand Down

0 comments on commit a1d5de1

Please sign in to comment.