Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BUG: missing error on name without leading / #2387

Merged
merged 27 commits into from
Feb 27, 2024
Merged
Show file tree
Hide file tree
Changes from 21 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions pypdf/_writer.py
Original file line number Diff line number Diff line change
Expand Up @@ -1898,15 +1898,15 @@ def add_uri(

border_arr: BorderArrayType
if border is not None:
border_arr = [NameObject(n) for n in border[:3]]
border_arr = [NumberObject(n) for n in border[:3]]
if len(border) == 4:
dash_pattern = ArrayObject([NameObject(n) for n in border[3]])
dash_pattern = ArrayObject([NumberObject(n) for n in border[3]])
border_arr.append(dash_pattern)
else:
border_arr = [NumberObject(2), NumberObject(2), NumberObject(2)]

if isinstance(rect, str):
rect = NameObject(rect)
rect = NumberObject(rect)
elif isinstance(rect, RectangleObject):
pass
else:
Expand Down
6 changes: 3 additions & 3 deletions pypdf/annotations/_markup_annotations.py
Original file line number Diff line number Diff line change
Expand Up @@ -165,8 +165,8 @@ def __init__(
),
NameObject("/LE"): ArrayObject(
[
NameObject(None),
NameObject(None),
NameObject("/None"),
NameObject("/None"),
Rak424 marked this conversation as resolved.
Show resolved Hide resolved
]
),
NameObject("/IC"): ArrayObject(
Expand Down Expand Up @@ -290,7 +290,7 @@ def __init__(
NameObject("/Type"): NameObject("/Annot"),
NameObject("/Subtype"): NameObject("/Polygon"),
NameObject("/Vertices"): ArrayObject(coord_list),
NameObject("/IT"): NameObject("PolygonCloud"),
NameObject("/IT"): NameObject("/PolygonCloud"),
NameObject("/Rect"): RectangleObject(_get_bounding_rectangle(vertices)),
}
)
Expand Down
10 changes: 7 additions & 3 deletions pypdf/generic/_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,13 @@
logger_warning,
read_non_whitespace,
read_until_regex,
str_,
str_, deprecate,
)
from ..errors import (
STREAM_TRUNCATED_PREMATURELY,
PdfReadError,
PdfStreamError,
)
from ..errors import STREAM_TRUNCATED_PREMATURELY, PdfReadError, PdfStreamError

__author__ = "Mathieu Fenniak"
__author_email__ = "biziqe@mathieu.fenniak.net"
Expand Down Expand Up @@ -615,7 +619,7 @@
def renumber(self) -> bytes:
out = self[0].encode("utf-8")
if out != b"/":
logger_warning(f"Incorrect first char in NameObject:({self})", __name__)
deprecate(f"Incorrect first char in NameObject, should start with '/':({self})")

Check warning on line 622 in pypdf/generic/_base.py

View check run for this annotation

Codecov / codecov/patch

pypdf/generic/_base.py#L622

Added line #L622 was not covered by tests
Rak424 marked this conversation as resolved.
Show resolved Hide resolved
for c in self[1:]:
if c > "~":
for x in c.encode("utf-8"):
Expand Down
5 changes: 2 additions & 3 deletions tests/test_generic.py
Original file line number Diff line number Diff line change
Expand Up @@ -219,9 +219,8 @@ def test_name_object(caplog):

caplog.clear()
b = BytesIO()
NameObject("hello").write_to_stream(b)
assert bytes(b.getbuffer()) == b"hello"
assert "Incorrect first char" in caplog.text
# with pytest.raises(PyPdfError) as exc: TODO
Rak424 marked this conversation as resolved.
Show resolved Hide resolved
# NameObject("hello").write_to_stream(b)

caplog.clear()
b = BytesIO()
Expand Down
Loading