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 25 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
2 changes: 1 addition & 1 deletion pypdf/generic/_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -615,7 +615,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__)
deprecate_no_replacement(f"Incorrect first char in NameObject, should start with '/':({self})","5.0.0")
stefan6419846 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(DeprecationWarning):
NameObject("hello").write_to_stream(b)

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