Created
August 9, 2016 17:58
-
-
Save 7LayersDesign/ed402d78419e0242ed2e77c07189ad95 to your computer and use it in GitHub Desktop.
DFP Key Cleaning
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| var _cleanValue = function(val) { | |
| // Convert pipes and spaces to underscores | |
| val = val.replace(/\|/g, "_"); | |
| val = val.replace(/\ /g, "_"); | |
| val = val.replace(/\-/g, "_"); | |
| // Strip out any other bad characters. | |
| val = val.replace(/\;/g, ""); | |
| val = val.replace(/\&/g, ""); | |
| val = val.replace(/\\/g, ""); | |
| val = val.replace(/\//g, ""); | |
| var invalidChars = "#\",*.()=+<>[]| "; | |
| var encodeChars = "$-_."; | |
| var valChars = val.split(""); | |
| var chars = []; // Final set of valid characters | |
| var arrLen = valChars.length; | |
| var curChar; | |
| for (var i = 0; i < valChars.length; i++) { | |
| curChar = valChars[i]; | |
| // Check if invalid | |
| if( invalidChars.indexOf(curChar) === -1 ){ | |
| // check if needs encoding | |
| if( encodeChars.indexOf(curChar) > -1 ){ | |
| // Needs escaping | |
| chars.push(escape(curChar)); | |
| } else { | |
| // Valid and safe | |
| chars.push(valChars[i]); | |
| } | |
| } | |
| } | |
| // join chars and return | |
| return chars.join(""); | |
| }; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment