Skip to content

fix: use shared validators in merge, split and protect PDF endpoints#297

Merged
Durgeshwar-AI merged 1 commit into
Durgeshwar-AI:mainfrom
pericharlabindhumadhavi-data:fix/273-pdf-file-validation
Jun 14, 2026
Merged

fix: use shared validators in merge, split and protect PDF endpoints#297
Durgeshwar-AI merged 1 commit into
Durgeshwar-AI:mainfrom
pericharlabindhumadhavi-data:fix/273-pdf-file-validation

Conversation

@pericharlabindhumadhavi-data

Copy link
Copy Markdown
Contributor

🔀 Pull Request

📌 Issue Reference

Closes #273


📝 Summary

Problem

The PDF Merge, Split, and Protect endpoints were using manual .pdf extension checks instead of the shared validation helpers available in utils/validators.py.

This caused:

  • Duplicate validation logic across multiple files.
  • Inconsistent validation behavior compared to other endpoints.
  • The Merge PDF endpoint did not handle fitz.FileDataError, which could lead to errors when corrupted PDF files were uploaded.

Solution

This PR replaces the manual PDF validation logic with the shared validate_uploaded_file() and validate_pdf_file() helper functions.

Additionally, merge_pdf.py now catches fitz.FileDataError and returns a user-friendly error message when an invalid or corrupted PDF is uploaded.

Changes Made

  • Imported and used validate_uploaded_file().
  • Imported and used validate_pdf_file().
  • Removed manual .endswith(".pdf") validation checks.
  • Added fitz.FileDataError handling in merge_pdf.py.
  • Standardized validation across Merge, Split, and Protect PDF endpoints.

✅ Checklist

  • My code follows the project's coding conventions
  • I have tested all impacted features
  • I have updated or added necessary documentation

🔗 Related Issues / PRs


🏅 Open Source Program Participation

Program Name: GSSoC 2026 (GirlScript Summer of Code)


💬 Additional Notes

Testing Performed

  • Uploaded valid PDF files and verified successful processing.
  • Uploaded non-PDF files and verified validation errors.
  • Uploaded corrupted PDF files and verified proper error handling.
  • Tested Merge, Split, and Protect PDF workflows after the changes.

@vercel

vercel Bot commented Jun 12, 2026

Copy link
Copy Markdown

@pericharlabindhumadhavi-data is attempting to deploy a commit to the Durgeshwar's projects Team on Vercel.

A member of the Team first needs to authorize it.

@Durgeshwar-AI

Copy link
Copy Markdown
Owner

@pericharlabindhumadhavi-data please fix the merge conflicts.

…F endpoints, remove split_pdf.py deleted in upstream
@pericharlabindhumadhavi-data

Copy link
Copy Markdown
Contributor Author

Hi @Durgeshwar-AI!
I have resolved all the merge conflicts. The branch is clean and ready for review.
Thank you!

@Durgeshwar-AI Durgeshwar-AI merged commit 04aba0a into Durgeshwar-AI:main Jun 14, 2026
2 of 3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG] PDF Merge, Split, and Protect use only filename extension check — no real file validation

2 participants