keichi / binary-parser

A blazing-fast declarative parser builder for binary data
MIT License
857 stars 134 forks source link

Bugfix: Make `pointer` accept offset=0 #255

Closed DominicChm closed 3 months ago

DominicChm commented 3 months ago

The current version of binary-parser has a type-coercion problem where an offset of 0 will incorrectly be rejected by .pointer. It's caused by this block which coerces offset=0 into false.

    if (!options.offset) {
      throw new Error("offset is required for pointer.");
    }

This PR simply replaces that check with one that accepts 0 but rejects both undefined and null (undefined == null = true)

keichi commented 3 months ago

Good catch, thank you! Can you fix the formatting changes that slipped in? You just need to run npm run format:fix.

DominicChm commented 3 months ago

Oops! Should be fixed now.