Closed dominicbarnes closed 9 years ago
This will break when this.src
or this.raw
are null
, or object
from some reason. More robust would be flipping the equals and type checking a string, which doesn't leave any holes that might cause errors:
if (typeof this.raw !== 'string')
Or maybe they can be Buffer objects and you need just an undefined check? Dunno the internals, but if that's the case, rather do double equals null, which checks null and undefined (see double equality table). Dunno how eslit, but this is the only double equals usage where jshint doesn't complain, because it's that useful.
@darsain I've gone ahead and allowed == null
by updating the ESLint config. This matches what we had before, which means it should still fix the underlying issue.
Any reason for not doing the most robust typeof this.raw !== 'string'
type check?
@darsain Hmm, I'm open to that possibility. What I have here works, so I'm going to press on with merging it, we can change it later if it turns out to be a problem.
If you guys find a bug in this implementation, please submit a PR with a breaking test.
I've made the code checking
raw
andsrc
a little more specific and clear. I believe I introduced this bug when I used ESLint to remove== undefined
from these spots.Basically, I've made the code a bit longer, but it should be a lot easier to maintain. (this fixes #484 and adds a test so it won't regress again)
/cc @darsain