Skip to content

Conversation

KyleJung0828
Copy link
Contributor

@KyleJung0828 KyleJung0828 commented Aug 26, 2025

Resolves #3446

How to check

As mentioned in #3446 you can test with guwunmong.pdf.

>>> import os
>>> from io import BytesIO
>>> from pypdf import PdfReader
>>> with open("guwunmong.pdf", "rb") as f:
...     pdf_bytes = f.read()
>>> reader = PdfReader(stream=BytesIO(pdf_bytes))
>>> metadata = reader.metadata
>>> creation_date = str(metadata.creation_date) if metadata.creation_date else None  # Used to raise IndexError here.
>>> creation_date
>>> print(creation_date)  # Prints None as expected.
None

Copy link

codecov bot commented Aug 26, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 96.97%. Comparing base (bc318d7) to head (415b04b).
⚠️ Report is 2 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #3448   +/-   ##
=======================================
  Coverage   96.97%   96.97%           
=======================================
  Files          54       54           
  Lines        9337     9337           
  Branches     1711     1711           
=======================================
  Hits         9055     9055           
  Misses        168      168           
  Partials      114      114           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@stefan6419846
Copy link
Collaborator

Thanks for the PR. Could you please add a corresponding test as well?

@stefan6419846 stefan6419846 added the needs-test A test should be added before this PR is merged. label Aug 26, 2025
@KyleJung0828
Copy link
Contributor Author

@stefan6419846
Sure. Do I just write a simple test function that tests text='' case, similar to what test_parse_datetime_err does? (No need to add guwunmong.pdf to sample-files repo?)

@stefan6419846
Copy link
Collaborator

You can either add a unit test without a PDF file or an integration test with downloading the PDF file on the fly (see other tests). If possible, I consider a unit test suitable enough here.

- Resolves py-pdf#3446
- Handle empty string case
- Add a unit test for edge cases
@KyleJung0828
Copy link
Contributor Author

@stefan6419846
I added a simple unit test for edge cases like "" and None as inputs (I rebased and squashed with the old commit for history). Let me know if something needs to be changed.

Copy link
Collaborator

@stefan6419846 stefan6419846 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks.

@stefan6419846 stefan6419846 merged commit e1b3b42 into py-pdf:main Sep 8, 2025
16 checks passed
stefan6419846 added a commit that referenced this pull request Sep 21, 2025
## What's new

### New Features (ENH)
- Enhance XMP metadata handling with creation and setter methods (#3410) by @Arya-A-Nair
- Add all font metrics for base 14 Type 1 PDF fonts (#3363) by @PJBrs
- Allow deleting embedded files (#3461) by @stefan6419846
- Add support for Python in FIPS mode for document identifier (#3438) by @xnox

### Bug Fixes (BUG)
- Fix handling of UTF-16 encoded destination titles (#3463) by @stefan6419846
- Guard empty input to prevent IndexError (#3448) by @KyleJung0828

### Developer Experience (DEV)
- Fix type hint for XMP metadata setter to add bytes type (#3464) by @stefan6419846

[Full Changelog](6.0.0...6.1.0)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs-test A test should be added before this PR is merged.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

IndexError when parsing creation_date
2 participants