Fix(routing): add protections against malformed data
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
import { compose } from 'redux';
|
||||
import { bonfire, html, js } from '../../utils/challengeTypes';
|
||||
import protect from '../../utils/empty-protector';
|
||||
|
||||
export function encodeScriptTags(value) {
|
||||
return value
|
||||
@@ -78,19 +79,6 @@ export function loggerToStr(args) {
|
||||
.reduce((str, arg) => str + arg + '\n', '');
|
||||
}
|
||||
|
||||
export function getFirstChallenge(
|
||||
{ superBlock, block, challenge },
|
||||
result
|
||||
) {
|
||||
return challenge[
|
||||
block[
|
||||
superBlock[
|
||||
result[0]
|
||||
].blocks[0]
|
||||
].challenges[0]
|
||||
];
|
||||
}
|
||||
|
||||
export function getNextChallenge(
|
||||
current,
|
||||
entities,
|
||||
@@ -285,20 +273,6 @@ export function getMouse(e, [dx, dy]) {
|
||||
return [pageX - dx, pageY - dy];
|
||||
}
|
||||
|
||||
const emptyProtector = {
|
||||
blocks: [],
|
||||
challenges: []
|
||||
};
|
||||
// protect against malformed data
|
||||
function protect(block) {
|
||||
// if no block or block has no challenges or blocks
|
||||
// use protector
|
||||
if (!block || !(block.challenges || block.blocks)) {
|
||||
return emptyProtector;
|
||||
}
|
||||
return block;
|
||||
}
|
||||
|
||||
// interface Node {
|
||||
// isHidden: Boolean,
|
||||
// children: Void|[ ...Node ],
|
||||
|
Reference in New Issue
Block a user