pdf-lib icon indicating copy to clipboard operation
pdf-lib copied to clipboard

Fix NaN validation

Open SkyaTura opened this issue 1 year ago • 1 comments

What?

This PR fixes a bug on utility validators where any parameters validated with assertIs would fail asserting Arrays because of unguarded isNaN call.

Why?

I don't really know how this is working at all for anyone, since I don't know how isNaN could return false for anything but a number.

How?

  1. Don't use globalThis.isNaN since it is meant to check values of ANY type. Use Number.isNaN instead. This alone should do the trick anyway.
  2. Move the isNaN clause inside the typeof number clause. This is solely for optimization...

Testing?

I'm pretty confidente that the this PR won't break anything. What I don't know is how is working anywhere, haha

New Dependencies?

Screenshots

Suggested Reading?

https://stackoverflow.com/questions/33164725/confusion-between-isnan-and-number-isnan-in-javascript

Anything Else?

Checklist

  • [X] I read CONTRIBUTING.md.
  • [X] I read MAINTAINERSHIP.md#pull-requests.
  • [ ] I added/updated unit tests for my changes.
  • [ ] I added/updated integration tests for my changes.
  • [ ] I ran the integration tests.
  • [ ] I tested my changes in Node, Deno, and the browser.
  • [ ] I viewed documents produced with my changes in Adobe Acrobat, Foxit Reader, Firefox, and Chrome.
  • [ ] I added/updated doc comments for any new/modified public APIs.
  • [X] My changes work for both new and existing PDF files.
  • [ ] I ran the linter on my changes.

SkyaTura avatar Jan 23 '25 13:01 SkyaTura

Will be solved in v2.5.3 of @cantoo/pdf-lib

Sharcoux avatar Sep 19 '25 19:09 Sharcoux