Busy.org Bug: Post with no json_metadata crashes the whole page

Project Information

Expected behavior

When a post doesn't contain any json_metadata the site should continue to work as normal.

Actual behavior

Any piece of code that tries to read a property of the JSON object when it's null will cause an error and the app will crash.

An example is

if (_.indexOf(postMetaData.app, 'steemit') === 0) {
  canonicalHost = 'https://steemit.com';
}

postMetaData.app will cause an error which is what can be seen in the developer console.
image.png

How to reproduce

If you got to a post with no json_metadata like this one @steemed/dan-cant-censor-with-51pct the whole page crashes. If you go to a user who's reblogged it such as @berniesanders the page crashes once that post is rendered

ads
An example of a post with empty metadata

Recording Of The Bug

Crash when you visit the post

Crash when you visit the blog of someone who's reblogged the post

Possible solution

The easiest solution is to check whether the parsed json_metadata is null before trying to read properties from it. The project uses lodash so

if (_.indexOf(postMetaData.app, 'steemit') === 0) {
  canonicalHost = 'https://steemit.com';
}

could become

if (_.isNull(postMetaData) || _.indexOf(postMetaData.app, 'steemit') === 0) {
  canonicalHost = 'https://steemit.com';
}

However there are many ways to fix this bug so the developers may choose a different solution.

GitHub Account

https://github.com/jrawsthorne

H2
H3
H4
3 columns
2 columns
1 column
8 Comments