Skip to content

Commit

Permalink
BUG: missing error on name without leading / (#2387)
Browse files Browse the repository at this point in the history
* handling name without leading /

* init

* type

* optional

* exception

* test

* test

* test

* missing /

* wrong name value

* wrong object

* wrong object

* Update tests/test_generic.py

Co-authored-by: pubpub-zz <4083478+pubpub-zz@users.noreply.github.com>

* indent

* deprecate

* ruff

* deprecate_no_replacement

* cleaning

* fix formatting and version

---------

Co-authored-by: francois <francois@rcdevs.com>
Co-authored-by: pubpub-zz <4083478+pubpub-zz@users.noreply.github.com>
Co-authored-by: Stefan <96178532+stefan6419846@users.noreply.github.com>
  • Loading branch information
4 people committed Feb 27, 2024
1 parent abfff1b commit 178014e
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 10 deletions.
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"),
]
),
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})", "6.0.0")
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

0 comments on commit 178014e

Please sign in to comment.