Human-Connection/API

`yarn run mocha` -> cannot read property '0' of undefined

Closed this issue · 4 comments

This line raises an error in some library used for sanitation. What's the purpose of this line?

We have to compare the string before truncating and after to see if the length changed significantly. But as the trunc method formats the string we need to first get the identical formatting bit without truncating.

Logging the error gives me:

{ TypeError: Cannot read property '0' of undefined
[1]     at testUrl (/home/robert/Development/human-connection/api/node_modules/insane/sanitizer.js:87:21)
[1]     at parse (/home/robert/Development/human-connection/api/node_modules/insane/sanitizer.js:53:84)
[1]     at Array.forEach (<anonymous>)
[1]     at Object.start (/home/robert/Development/human-connection/api/node_modules/insane/sanitizer.js:40:24)
[1]     at parseStartTag (/home/robert/Development/human-connection/api/node_modules/insane/parser.js:103:15)
[1]     at String.replace (<anonymous>)
[1]     at parseEdge (/home/robert/Development/human-connection/api/node_modules/insane/parser.js:58:16)
[1]     at parseTag (/home/robert/Development/human-connection/api/node_modules/insane/parser.js:49:7)
[1]     at parsePart (/home/robert/Development/human-connection/api/node_modules/insane/parser.js:33:5)
[1]     at parser (/home/robert/Development/human-connection/api/node_modules/insane/parser.js:27:5)
[1]     at insane (/home/robert/Development/human-connection/api/node_modules/insane/insane.js:14:3)
[1]     at truncHtml (/home/robert/Development/human-connection/api/node_modules/trunc-html/index.js:25:14)
[1]     at Object.<anonymous> (/home/robert/Development/human-connection/api/server/hooks/create-excerpt.js:37:29)
[1]     at process._tickCallback (internal/process/next_tick.js:68:7)
[1]   level: 'error',
[1]   [Symbol(level)]: 'error',
[1]   [Symbol(message)]: '{"level":"error"}' }

Could be another issue related to a plugin.

Issue seems to come from content without text but only with html link. This results in an empty truncated string.

We should fix the need for plane content and accept also links. But we have to test that with the content display on the newsfeed.

Fixed by dont throwing an error inside the hook. If the process results in no excerpt, the schema validation schould throw a better message anyway.