Redactor crashes NodeBB
-
Hi @baris ,
The category is defined. The problem is the access to the array cidToCategory.
I reviewed its content with the debugger, and the c.parent.cid cannot be used to access it:
cidToCategory does not have linear index that matches the internal cid:Index: Data: 1: {cid: 1, icon: "hidden", link: "", …} 2: {cid: 31, icon: "hidden", link:…} 3: {cid: 9, icon: …} 4: {cid: 37, icon: "hidden", link: …}
Furthermore, Some parts of the array is undefined.
This is the definition of cidToCategory :
var cidToCategory = _.zipObject(cids, results.categories);
The bad access occures in line 128, where the cid is used:
cidToCategory[c.parent.cid].children = cidToCategory[c.parent.cid].children.filter(child => { return child.cid !== c.cid;
-
@JJSagan Hmm that's definitely weird
cidToCategory
should be an object with the keys being category ids.On my environment I get this.
{ '1': { bgColor: '#fda34b', cid: 1, class: 'col-md-3 col-xs-6', color: '#fff', description: 'Announcements regarding our community', descriptionParsed: '<p>Announcements regarding our community</p>\n', disabled: 0, icon: 'fa-bullhorn', imageClass: 'cover', isSection: 0, link: '', name: 'Announcements', numRecentReplies: 1, order: 1, parentCid: 0, post_count: 33, slug: '1/announcements', topic_count: 5, totalPostCount: 33, totalTopicCount: 5, children: [], parent: undefined }, '2': { bgColor: '#59b3d0', cid: 2, class: 'col-md-3 col-xs-6', color: '#fff', description: 'A place to talk about whatever you want', descriptionParsed: '<p>A place to talk about whatever you want</p>\n', disabled: 0, icon: 'fa-comments-o', imageClass: 'cover', isSection: 0, link: '', name: 'General Discussion', numRecentReplies: 1, order: 2, parentCid: 0, post_count: 20, slug: '2/general-discussion', topic_count: 7, totalPostCount: 20, totalTopicCount: 7, children: [ [Object] ], parent: undefined }, '3': { bgColor: '#86ba4b', cid: 3, class: 'col-md-3 col-xs-6', color: '#fff', description: 'Blog posts from individual members', descriptionParsed: '<p>Blog posts from individual members</p>\n', disabled: 0, icon: 'fa-newspaper-o', imageClass: 'cover', isSection: 0, link: '', name: 'Blogs', ...
-
Hi @baris ,
From what I see, the categories on my setup are well defined and working. I also made a quick check with group privileges - to make sure access is granted to the target category, and it looks like we are ok.
I may have, over time, obsoleted several categories, and maybe later returned some or all to active duty. Thus, the cid array may not be perfectly "linear".
Another direction: I am using postgress, so maybe the array that is fetched from the DB is not sorted. I hope @Ben-Lubar might be able to shed some light here.
Thanks again for looking into this! highly appreciated.
-
@baris said in Redactor crashes NodeBB:
console.log(cids, cidToCategory);
It looks good. As far as I can tell, all items are valid. The issue is that the array index (below, for example first line: 37), does not matches internal cid (below, 2nd line: 10). Thus, the array may not be accessed with the c.parent.cid.
Perhaps we need to sort the array first, or use filter?
Console.log output:
'37': { cid: 10, icon: 'hidden', link: '', ... } }, '38': { cid: 34, icon: 'hidden', link: '', ... } }, '39': { cid: 40, icon: 'hidden', link: '',