Skip to content

Commit

Permalink
Check self.cur_item._objs length before [-1]
Browse files Browse the repository at this point in the history
In theory shouldn't happen, but came across a malformed PDF that threw
an error here; simple enough check that seemed worth adding.
  • Loading branch information
jsvine committed Feb 10, 2024
1 parent f73fbe1 commit 4f39d03
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions pdfplumber/page.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,9 +147,10 @@ def tag_cur_item(self) -> None:
# create one object, but that is far from being guaranteed.
# Even if pdfminer.six's API would just return the objects it
# creates, we wouldn't have to do this.
cur_obj = self.cur_item._objs[-1]
cur_obj.mcid = self.cur_mcid # type: ignore
cur_obj.tag = self.cur_tag # type: ignore
if self.cur_item._objs:
cur_obj = self.cur_item._objs[-1]
cur_obj.mcid = self.cur_mcid # type: ignore
cur_obj.tag = self.cur_tag # type: ignore

def render_char(self, *args, **kwargs) -> float: # type: ignore
"""Hook for rendering characters, adding the `mcid` attribute."""
Expand Down

0 comments on commit 4f39d03

Please sign in to comment.