Fix content decoding
This commit is contained in:
@ -3,6 +3,7 @@ import { createPoly } from '../../../../utils/polyvinyl';
|
|||||||
|
|
||||||
import types from './types';
|
import types from './types';
|
||||||
import { HTML, JS } from '../../../utils/challengeTypes';
|
import { HTML, JS } from '../../../utils/challengeTypes';
|
||||||
|
import { buildSeed, getPath } from '../utils';
|
||||||
|
|
||||||
const initialState = {
|
const initialState = {
|
||||||
challenge: '',
|
challenge: '',
|
||||||
@ -13,24 +14,6 @@ const initialState = {
|
|||||||
superBlocks: []
|
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(
|
const mainReducer = handleActions(
|
||||||
{
|
{
|
||||||
[types.fetchChallengeCompleted]: (state, { payload = '' }) => ({
|
[types.fetchChallengeCompleted]: (state, { payload = '' }) => ({
|
||||||
|
50
common/app/routes/challenges/utils.js
Normal file
50
common/app/routes/challenges/utils.js
Normal 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';
|
||||||
|
}
|
||||||
|
|
Reference in New Issue
Block a user