diff --git a/common/app/routes/challenges/redux/reducer.js b/common/app/routes/challenges/redux/reducer.js index 068de2aedf..27b009e2b1 100644 --- a/common/app/routes/challenges/redux/reducer.js +++ b/common/app/routes/challenges/redux/reducer.js @@ -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 = '' }) => ({ diff --git a/common/app/routes/challenges/utils.js b/common/app/routes/challenges/utils.js new file mode 100644 index 0000000000..9959f48455 --- /dev/null +++ b/common/app/routes/challenges/utils.js @@ -0,0 +1,50 @@ +import { compose } from 'redux'; +import { HTML, JS } from '../../utils/challengeTypes'; + +export function encodeScriptTags(value) { + return value + .replace(/'); +} + +export function encodeFormAction(value) { + return value.replace( + /]*>/, + val => val.replace(/action(\s*?)=/, 'fccfaa$1=') + ); +} + +export function decodeFccfaaAttr(value) { + return value.replace( + /]*>/, + 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'; +} +