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

fix: allow to parse null or empty header element #560

Merged
merged 8 commits into from
Dec 5, 2022

Conversation

EnThib
Copy link
Contributor

@EnThib EnThib commented Nov 23, 2022

Why I open this pull request ?

When I pass a empty string value at the first arguments of parseHeader function, it throw an exception :

Argument 1 passed to Smalot\PdfParser\Parser::parseHeader() must be of the type array, string given, called in /path/to/project/vendor/smalot/pdfparser/src/Smalot/PdfParser/Parser.php on line 266

that append when I provide a PDF like this : 20221025_debug_header_parse.pdf

If it helps, I have already opened a case for this problem. : #557

Have a good day ^^

@k00ni k00ni linked an issue Nov 23, 2022 that may be closed by this pull request
Copy link
Collaborator

@k00ni k00ni left a comment

Choose a reason for hiding this comment

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

@DogLoc thank you for this fix. I have a few things:

  • Can you move the new if-clause before the switch-clause? I can not see why this check is only relevant for the >> case.
  • Please provide at least one test. If you need help here, let me know.
  • Please fix failing CS workflow by running PHP-CS-Fixer.
  • Out of curiosity: why not return ElementNull instead? Why do you use null?

@EnThib
Copy link
Contributor Author

EnThib commented Nov 24, 2022

@DogLoc thank you for this fix. I have a few things:

  • Can you move the new if-clause before the switch-clause? I can not see why this check is only relevant for the >> case.
  • Please provide at least one test. If you need help here, let me know.
  • Please fix failing CS workflow by running PHP-CS-Fixer.
  • Out of curiosity: why not return ElementNull instead? Why do you use null?

Finally I use an empty array for input and output (<<, >>) because with the ElementNull class, the code tries to retrieve the header on a null element I don't have strong knowledge of this project, so if you have a better suggestion, I take it! ^^

I have provided a unit test for the parser, let me know if this is sufficient.

@EnThib
Copy link
Contributor Author

EnThib commented Nov 28, 2022

@k00ni master merged in my branch 👍

@EnThib EnThib requested a review from k00ni November 30, 2022 16:51
Copy link
Collaborator

@k00ni k00ni left a comment

Choose a reason for hiding this comment

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

Thank you for your changes! There is only one thing and we are good to go.

src/Smalot/PdfParser/Parser.php Outdated Show resolved Hide resolved
@k00ni k00ni self-assigned this Dec 2, 2022
Co-authored-by: Konrad Abicht <hi@inspirito.de>
@k00ni k00ni removed the needs work label Dec 2, 2022
@k00ni
Copy link
Collaborator

k00ni commented Dec 2, 2022

Looks good to me. I will merge it next week if there are no objections.

Thank you @DogLoc!

@EnThib
Copy link
Contributor Author

EnThib commented Dec 2, 2022

Thanks you too ^^ ! @k00ni

@k00ni k00ni merged commit e2e3581 into smalot:master Dec 5, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

I have a error when i use parseFile function
2 participants