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 13 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
10 changes: 5 additions & 5 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 Expand Up @@ -325,9 +325,9 @@ def __init__(

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(0)] * 3
Expand Down
9 changes: 7 additions & 2 deletions pypdf/generic/_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,12 @@
read_until_regex,
str_,
)
from ..errors import STREAM_TRUNCATED_PREMATURELY, PdfReadError, PdfStreamError
from ..errors import (
STREAM_TRUNCATED_PREMATURELY,
PdfReadError,
PdfStreamError,
PyPdfError,
)

__author__ = "Mathieu Fenniak"
__author_email__ = "biziqe@mathieu.fenniak.net"
Expand Down Expand Up @@ -589,7 +594,7 @@ def write_to_stream(
def renumber(self) -> bytes:
out = self[0].encode("utf-8")
if out != b"/":
logger_warning(f"Incorrect first char in NameObject:({self})", __name__)
raise PyPdfError(f"Incorrect first char in NameObject:({self})", __name__)
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
10 changes: 6 additions & 4 deletions tests/test_generic.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

from pypdf import PdfMerger, PdfReader, PdfWriter
from pypdf.constants import CheckboxRadioButtonAttributes
from pypdf.errors import PdfReadError, PdfStreamError
from pypdf.errors import PdfReadError, PdfStreamError, PyPdfError
from pypdf.generic import (
AnnotationBuilder,
ArrayObject,
Expand Down Expand Up @@ -218,9 +218,11 @@ 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
try:
NameObject("hello").write_to_stream(b)
pytest.fail("Corrupted name object")
except PyPdfError:
pass
Rak424 marked this conversation as resolved.
Show resolved Hide resolved

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