Fix(routing): add protections against malformed data

This commit is contained in:
Berkeley Martinez
2016-08-05 14:49:23 -07:00
parent 91a50b4843
commit 3d05eee0ea
4 changed files with 84 additions and 55 deletions

View File

@@ -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 ],