twozeroone / post-type-discovery

Implementation of post type discovery W3C spec
https://post-type-discovery.js.org/
BSD 3-Clause "New" or "Revised" License
5 stars 1 forks source link

Note type posts throws Type Error: Cannot read property '0' of undefined #3

Open paulrobertlloyd opened 5 years ago

paulrobertlloyd commented 5 years ago

This package currently throws an error (shown below) if the provided mf2 object doesn’t include a name property, which is often the case for note type posts.

TypeError: Cannot read property '0' of undefined
    at getValue (/Users/paulrobertlloyd/Sites/indiekit/node_modules/post-type-discovery/index.js:12:15)
    at getType (/Users/paulrobertlloyd/Sites/indiekit/node_modules/post-type-discovery/index.js:74:14)
    at Object.module.exports [as createPost] (/Users/paulrobertlloyd/Sites/indiekit/app/lib/micropub/create-post.js:33:12)
    at getResult (/Users/paulrobertlloyd/Sites/indiekit/app/routes/micropub.js:88:23)
    at processTicksAndRejections (internal/process/next_tick.js:81:5)
paulrobertlloyd commented 5 years ago

Updating the following on line 74 fixes this issue:

- var name = getValue( prop.name );
+ var name = prop.name ? getValue( prop.name ) : undefined; 

Happy to make a PR if you feel this is the right approach.

prtksxna commented 5 years ago

Thanks for reporting the issues @paulrobertlloyd 🙂The approach looks correct, I'd be happy to merge a PR.

prtksxna commented 5 years ago

Do you have an example of when this happens? I tried a note from your website and it seems to contain the name: https://glennjones.net/tools/microformats/?url=https%3A%2F%2Fpaulrobertlloyd.com%2Fnotes%2F1563227099&callback=&dateformat=auto

I'd like to add it to the test suite so that there aren't any regressions in the future.