Fix content decoding

This commit is contained in:
Berkeley Martinez
2016-05-11 23:45:42 -07:00
parent 70dc2f75fa
commit f76eaf829f
2 changed files with 51 additions and 18 deletions

View File

@ -3,6 +3,7 @@ import { createPoly } from '../../../../utils/polyvinyl';
import types from './types';
import { HTML, JS } from '../../../utils/challengeTypes';
import { buildSeed, getPath } from '../utils';
const initialState = {
challenge: '',
@ -13,24 +14,6 @@ const initialState = {
superBlocks: []
};
function arrayToNewLineString(seedData = []) {
seedData = Array.isArray(seedData) ? seedData : [seedData];
return seedData.reduce((seed, line) => '' + seed + line + '\n', '');
}
function buildSeed({ challengeSeed = [] } = {}) {
return arrayToNewLineString(challengeSeed);
}
const pathsMap = {
[HTML]: 'main.html',
[JS]: 'main.js'
};
function getPath({ challengeType }) {
return pathsMap[challengeType] || 'main';
}
const mainReducer = handleActions(
{
[types.fetchChallengeCompleted]: (state, { payload = '' }) => ({

View File

@ -0,0 +1,50 @@
import { compose } from 'redux';
import { HTML, JS } from '../../utils/challengeTypes';
export function encodeScriptTags(value) {
return value
.replace(/<script>/gi, 'fccss')
.replace(/<\/script>/gi, 'fcces');
}
export function decodeSafeTags(value) {
return value
.replace(/fccss/gi, '<script>')
.replace(/fcces/gi, '</script>');
}
export function encodeFormAction(value) {
return value.replace(
/<form[^>]*>/,
val => val.replace(/action(\s*?)=/, 'fccfaa$1=')
);
}
export function decodeFccfaaAttr(value) {
return value.replace(
/<form[^>]*>/,
val => val.replace(/fccfaa(\s*?)=/, 'action$1=')
);
}
export function arrayToNewLineString(seedData = []) {
seedData = Array.isArray(seedData) ? seedData : [seedData];
return seedData.reduce((seed, line) => '' + seed + line + '\n', '\n');
}
export function buildSeed({ challengeSeed = [] } = {}) {
return compose(
decodeSafeTags,
arrayToNewLineString
)(challengeSeed);
}
const pathsMap = {
[HTML]: 'main.html',
[JS]: 'main.js'
};
export function getPath({ challengeType }) {
return pathsMap[challengeType] || 'main';
}