boazsegev / combine_pdf

A Pure ruby library to merge PDF files, number pages and maybe more...
MIT License
733 stars 154 forks source link

Add guard to prevent nil error while parsing octal notation #231

Closed jkowens closed 10 months ago

jkowens commented 10 months ago

While parsing a PDF, we ran into an issue where the the following error was raised:

NoMethodError: undefined method between? for nil:NilClass

We tracked it down to this line in the _parse_ method of PDFParser:

rep = (rep << 3) + (str_bytes.shift-48) if str_bytes[0].between?(48, 57)

It turns out there is potentially an error scenario while looping until str_bytes is empty where accessing str_bytes[0] would be a nil value. We just added the safe navigation operator which was added in Ruby 2.3. If this project is still supporting older rubies we can amend the commit.

boazsegev commented 10 months ago

Thanks!

Nicely Done! 🎉👏🏻👏🏻👏🏻