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

@ -0,0 +1,46 @@
import flow from 'lodash/flow';
// we don't store loop protect disable key
export function removeNoprotect(val) {
return val.replace(/noprotect/gi, '');
}
export function encodeScriptTags(val) {
return val
.replace(/<script>/gi, 'fccss')
.replace(/<\/script>/gi, 'fcces');
}
export function decodeScriptTags(val) {
return val
.replace(/fccss/gi, '<script>')
.replace(/fcces/gi, '</script>');
}
export function encodeFormAction(val) {
return val.replace(
// look for attributes in a form
/<form[^>]*>/,
// val is the string within the opening form tag
// look for an `action` attribute, replace it with a fcc tag
val => val.replace(/action(\s*?)=/, 'fccfaa$1=')
);
}
export function decodeFormAction(val) {
return val.replace(
/<form[^>]*>/,
val => val.replace(/fccfaa(\s*?)=/, 'action$1=')
);
}
export const encodeFcc = flow([
removeNoprotect,
encodeFormAction,
encodeScriptTags
]);
export const decodeFcc = flow([
decodeFormAction,
decodeScriptTags
]);