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

In parse check if sri is an object #14

Open
vjpr opened this issue Aug 14, 2018 · 0 comments
Open

In parse check if sri is an object #14

vjpr opened this issue Aug 14, 2018 · 0 comments

Comments

@vjpr
Copy link

vjpr commented Aug 14, 2018

https://github.com/zkat/ssri/blob/latest/index.js#L121-L133

module.exports.parse = parse
function parse (sri, opts) {
  opts = opts || {}
  if (typeof sri === 'string') {
    return _parse(sri, opts)
  } else if (sri.algorithm && sri.digest) {
    const fullSri = new Integrity()
    fullSri[sri.algorithm] = [sri]
    return _parse(stringify(fullSri, opts), opts)
  } else {
    return _parse(stringify(sri, opts), opts)
  }
}

There is a check for typeof string, then a check for sri.algorithm && ..., then an else condition.

I suggest checking if sri is an object before trying to access a property on it.

I understand that exhaustive type-checking of arguments adds noise, but in this case the function is doing some type checking already so it might make sense to be more explicit.

We had an issue over at pnpm where we didn't pass in the sri by accident. pnpm/pnpm#1324

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant