stacks.js: Ensure arrays are treated as such in zone-file dependency to prevent file parsing errors

I’m encountering the following error thrown by the zone-file dependency upon passing a username (“markmhendrickson.id” in my case) into getFile (see my invocation code here):

TypeError: Cannot read property 'length' of undefined
    at flatten (parseZoneFile.js:33)
    at parseZoneFile (parseZoneFile.js:9)
    at profileZoneFiles.js:76
    at new Promise (<anonymous>)
    at resolveZoneFileToProfile (profileZoneFiles.js:73)
    at profileLookup.js:38

The flatten method in that package (https://github.com/blockstack/zone-file-js/blob/master/src/parseZoneFile.es6#L16) seems to think that regex matches have been found in the text variable (which represents my zonefile correctly). So it enters the for-loop on line 31 before trying to get the length of match[0] which is undefined since captured is actually an empty array.

screen shot 2018-12-30 at 21 42 57

Note that when I omit the “username” parameter from the “getFile” method, I don’t encounter this error.

I can’t figure out what’s going on here. I thought maybe this was the result of not applying “publish_data” as a scope during authentication, but the same error persists even after adding it and re-authenticating with the same ID.

This can also be tested for recreation by going through the authentication flow on https://humans.name/ and viewing the console upon callback.

@kantai any ideas given your familiarity with the zone-file package?

About this issue

  • Original URL
  • State: closed
  • Created 6 years ago
  • Comments: 17

Most upvoted comments

Yep, please do!

zone-file-js was released at 1.0.0 — to include that in blockstack.js, the dependency will need to be updated.

Yep, once that’s reviewed, I’ll release zone-file-js. Then the dependency can be upgraded, tested in blockstack.js.

Yeah, definitely agree – I started a branch to refactor that library so that it’s structured similarly to our other libraries. Just using flow typing would have caused those uses of for-in to report errors.

So it looks like this issue is caused by the way zone-file-js is iterating over various objects combined with the use of a library which modifies Array.prototype