Feature(challenges): add code-uri utils

Fix(nav): points nav item propTypes
This commit is contained in:
Berkeley Martinez
2016-08-14 23:22:34 -07:00
parent 5fb2802e32
commit 3f3aab3ff7
4 changed files with 117 additions and 32 deletions

View File

@@ -1,42 +1,17 @@
import { compose } from 'redux';
import flow from 'lodash/flow';
import { bonfire, html, js } from '../../utils/challengeTypes';
import { decodeScriptTags } from '../../../utils/encode-decode';
import protect from '../../utils/empty-protector';
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 arrayToString(seedData = ['']) {
seedData = Array.isArray(seedData) ? seedData : [seedData];
return seedData.reduce((seed, line) => '' + seed + line + '\n', '\n');
}
export function buildSeed({ challengeSeed = [] } = {}) {
return compose(
decodeSafeTags,
arrayToString
return flow(
arrayToString,
decodeScriptTags
)(challengeSeed);
}