export evernote ok

This commit is contained in:
life
2015-10-26 17:57:00 +08:00
parent c60988da72
commit 45e79528b0
34 changed files with 5185 additions and 2 deletions

24
node_modules/resanitize/LICENSE generated vendored Normal file
View File

@@ -0,0 +1,24 @@
----------------------------------------------------------------------
resanitize is released under the MIT License
Copyright (c) 2012 Dan MacTough - http://yabfog.com
Permission is hereby granted, free of charge, to any person
obtaining a copy of this software and associated documentation
files (the "Software"), to deal in the Software without
restriction, including without limitation the rights to use,
copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the
Software is furnished to do so, subject to the following
conditions:
The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
OTHER DEALINGS IN THE SOFTWARE.

36
node_modules/resanitize/README.md generated vendored Normal file
View File

@@ -0,0 +1,36 @@
# Resanitize - Regular expression-based HTML sanitizer and ad remover, geared toward RSS feed descriptions
This node.js module provides functions for removing unsafe parts and ads from
HTML. I am using it for the <description> element of RSS feeds.
## Installation
npm install resanitize
## Usage
```javascript
var resanitize = require('resanitize')
, html = '<div style="border: 400px solid pink;">Headline</div>'
;
resanitize(html); // => '<div>Headline</div>'
```
## Notes
This module's opinion of "sanitized" might not meet your security requirements.
The mere fact that it uses regular expressions should make this disclaimer
unnecessary, but just to be clear: if you intend to display arbitrary user input
that includes HTML, you're going to want something more robust.
As of v0.3.0, we've added [node-validator's](//github.com/chriso/node-validator) XSS
filter. It's certainly an improvement, but still -- be careful. Any concerns
about XSS attacks should be directered to [node-validator's issue tracker](//github.com/chriso/node-validator/issues).
Note that the `stripUnsafeTags` method will loop over the strip an arbitrary
number of times (2) to try to strip maliciously nested html tags. After the
maximum number of iterations is reached, if the string still appears to contain
any unsafe tags, it is deemed unsafe and set to an empty string. If this seems
unexpected and/or is causing any problems, please raise an [issue](//github.com/danmactough/node-resanitize/issues).

View File

@@ -0,0 +1 @@
.DS_Store

20
node_modules/resanitize/node_modules/validator/LICENSE generated vendored Executable file
View File

@@ -0,0 +1,20 @@
Copyright (c) 2010 Chris O'Hara <cohara87@gmail.com>
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:
The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

249
node_modules/resanitize/node_modules/validator/README.md generated vendored Executable file
View File

@@ -0,0 +1,249 @@
**node-validator is a library of string validation, filtering and sanitization methods.**
To install node-validator, use [npm](http://github.com/isaacs/npm):
```bash
$ npm install validator
```
To use the library in the browser, include `validator-min.js`
## Example
```javascript
var check = require('validator').check,
sanitize = require('validator').sanitize
//Validate
check('test@email.com').len(6, 64).isEmail(); //Methods are chainable
check('abc').isInt(); //Throws 'Invalid integer'
check('abc', 'Please enter a number').isInt(); //Throws 'Please enter a number'
check('abcdefghijklmnopzrtsuvqxyz').is(/^[a-z]+$/);
//Set a message per validator
check('foo', {
isNumeric: 'This is not a number',
contains: 'The value doesn\'t have a 0 in it'
}).isNumeric().contains('0');
//Referencing validator args from the message
check('foo', 'The message needs to be between %1 and %2 characters long (you passed "%0")').len(2, 6);
//Sanitize / Filter
var int = sanitize('0123').toInt(); //123
var bool = sanitize('true').toBoolean(); //true
var str = sanitize(' \t\r hello \n').trim(); //'hello'
var str = sanitize('aaaaaaaaab').ltrim('a'); //'b'
var str = sanitize(large_input_str).xss();
var str = sanitize('&lt;a&gt;').entityDecode(); //'<a>'
```
## Web development
Often it's more desirable to check or automatically sanitize parameters by name (rather than the actual string). See [this gist](https://gist.github.com/752126) for instructions on binding the library to the `request` prototype.
If you are using the [express.js framework](https://github.com/visionmedia/express) you can use the [express-validator middleware](https://github.com/ctavan/express-validator) to seamlessly integrate node-validator.
Example `http://localhost:8080/?zip=12345&foo=1&textarea=large_string`
```javascript
get('/', function (req, res) {
req.onValidationError(function (msg) {
//Redirect the user with error 'msg'
});
//Validate user input
req.check('zip', 'Please enter a valid ZIP code').len(4,5).isInt();
req.check('email', 'Please enter a valid email').len(6,64).isEmail();
req.checkHeader('referer').contains('localhost');
//Sanitize user input
req.sanitize('textarea').xss();
req.sanitize('foo').toBoolean();
//etc.
});
```
## An important note
This library validates **strings** only. If you pass something that's not a string as input it will be coerced to a string using the following rules:
- Is it an object with a `toString` property? Call `input.toString()`
- Is it `null`, `undefined`, or `NaN`? Replace with an empty string
- All other input? Coerce to a string using `'' + input`
## List of validation methods
```javascript
is() //Alias for regex()
not() //Alias for notRegex()
isEmail()
isUrl() //Accepts http, https, ftp
isIP() //Combines isIPv4 and isIPv6
isIPv4()
isIPv6()
isAlpha()
isAlphanumeric()
isNumeric()
isHexadecimal()
isHexColor() //Accepts valid hexcolors with or without # prefix
isInt() //isNumeric accepts zero padded numbers, e.g. '001', isInt doesn't
isLowercase()
isUppercase()
isDecimal()
isFloat() //Alias for isDecimal
notNull() //Check if length is 0
isNull()
notEmpty() //Not just whitespace (input.trim().length !== 0)
equals(equals)
contains(str)
notContains(str)
regex(pattern, modifiers) //Usage: regex(/[a-z]/i) or regex('[a-z]','i')
notRegex(pattern, modifiers)
len(min, max) //max is optional
isUUID(version) //Version can be 3, 4 or 5 or empty, see http://en.wikipedia.org/wiki/Universally_unique_identifier
isUUIDv3() //Alias for isUUID(3)
isUUIDv4() //Alias for isUUID(4)
isUUIDv5() //Alias for isUUID(5)
isDate() //Uses Date.parse() - regex is probably a better choice
isAfter(date) //Argument is optional and defaults to today. Comparison is non-inclusive
isBefore(date) //Argument is optional and defaults to today. Comparison is non-inclusive
isIn(options) //Accepts an array or string
notIn(options)
max(val)
min(val)
isCreditCard() //Will work against Visa, MasterCard, American Express, Discover, Diners Club, and JCB card numbering formats
```
## List of sanitization / filter methods
```javascript
trim(chars) //Trim optional `chars`, default is to trim whitespace (\r\n\t )
ltrim(chars)
rtrim(chars)
ifNull(replace)
toFloat()
toInt()
toBoolean() //True unless str = '0', 'false', or str.length == 0
toBooleanStrict() //False unless str = '1' or 'true'
entityDecode() //Decode HTML entities
entityEncode()
escape() //Escape &, <, >, and "
xss() //Remove common XSS attack vectors from user-supplied HTML
xss(true) //Remove common XSS attack vectors from images
```
## Extending the library
When adding to the Validator prototype, use `this.str` to access the string and `this.error(this.msg || default_msg)` when the string is invalid
```javascript
var Validator = require('validator').Validator;
Validator.prototype.contains = function(str) {
if (!~this.str.indexOf(str)) {
this.error(this.msg || this.str + ' does not contain ' + str);
}
return this; //Allow method chaining
}
```
When adding to the Filter (sanitize) prototype, use `this.str` to access the string and `this.modify(new_str)` to update it
```javascript
var Filter = require('validator').Filter;
Filter.prototype.removeNumbers = function() {
this.modify(this.str.replace(/[0-9]+/g, ''));
return this.str;
}
```
## Error handling
By default, the validation methods throw an exception when a check fails
```javascript
try {
check('abc').notNull().isInt()
} catch (e) {
console.log(e.message); //Invalid integer
}
```
To set a custom error message, set the second param of `check()`
```javascript
try {
check('abc', 'Please enter a valid integer').notNull().isInt()
} catch (e) {
console.log(e.message); //Please enter a valid integer
}
```
To attach a custom error handler, set the `error` method of the validator instance
```javascript
var Validator = require('validator').Validator;
var v = new Validator();
v.error = function(msg) {
console.log('Fail');
}
v.check('abc').isInt(); //'Fail'
```
You might want to collect errors instead of throwing each time
```javascript
Validator.prototype.error = function (msg) {
this._errors.push(msg);
return this;
}
Validator.prototype.getErrors = function () {
return this._errors;
}
var validator = new Validator();
validator.check('abc').isEmail();
validator.check('hello').len(10,30);
var errors = validator.getErrors(); // ['Invalid email', 'String is too small']
```
## Contributors
- [zero21xxx](https://github.com/zero21xxx) - Added per check messages
- [PING](https://github.com/PlNG) - Fixed entity encoding
- [Dan VerWeire](https://github.com/wankdanker) - Modified the behaviour of the error handler
- [ctavan](https://github.com/ctavan) - Added isArray (since removed) and isUUID
- [foxbunny](https://github.com/foxbunny) - Added min(), max(), isAfter(), isBefore(), and improved isDate()
- [oris](https://github.com/orls) - Added in()
- [mren](https://github.com/mren) - Decoupled rules
- [Thorsten Basse](https://github.com/tbasse) - Cleanup and refinement of existing validators
- [Neal Poole](https://github.com/nealpoole) - Port the latest xss() updates from CodeIgniter
## LICENSE
(MIT License)
Copyright (c) 2010 Chris O'Hara <cohara87@gmail.com>
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:
The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

View File

@@ -0,0 +1,16 @@
<html>
<head>
<script type="text/javascript" src="validator-min.js"></script>
</head>
<body>
<script type="text/javascript">
try {
check('ad>dfds@fsdfsd.com').isEmail();
} catch (e) {
console.log('ok');
}
console.log(sanitize('aaa<a>bbb</a>').xss());
console.log(sanitize('aaa<a>bbb</a>').escape());
</script>
</body>
</html>

1
node_modules/resanitize/node_modules/validator/index.js generated vendored Executable file
View File

@@ -0,0 +1 @@
exports = module.exports = require('./lib');

View File

@@ -0,0 +1,37 @@
var defaultError = module.exports = {
isEmail: 'Invalid email',
isUrl: 'Invalid URL',
isIP: 'Invalid IP',
isAlpha: 'Invalid characters',
isAlphanumeric: 'Invalid characters',
isHexadecimal: 'Invalid hexadecimal',
isHexColor: 'Invalid hexcolor',
isNumeric: 'Invalid number',
isLowercase: 'Invalid characters',
isUppercase: 'Invalid characters',
isInt: 'Invalid integer',
isDecimal: 'Invalid decimal',
isDivisibleBy: 'Not divisible',
notNull: 'String is empty',
isNull: 'String is not empty',
notEmpty: 'String is empty',
equals: 'Not equal',
contains: 'Invalid characters',
notContains: 'Invalid characters',
regex: 'Invalid characters',
notRegex: 'Invalid characters',
len: 'String is not in range',
isUUID: 'Not a UUID',
isUUIDv3: 'Not a UUID v3',
isUUIDv4: 'Not a UUID v4',
isUUIDv5: 'Not a UUID v5',
isDate: 'Not a date',
isAfter: 'Invalid date',
isBefore: 'Invalid date',
isIn: 'Unexpected value or invalid argument',
notIn: 'Unexpected value or invalid argument',
min: 'Invalid number',
max: 'Invalid number',
isCreditCard: 'Invalid credit card'
};

View File

@@ -0,0 +1,290 @@
var entities = {
'&nbsp;': '\u00a0',
'&iexcl;': '\u00a1',
'&cent;': '\u00a2',
'&pound;': '\u00a3',
'&euro;': '\u20ac',
'&yen;': '\u00a5',
'&brvbar;': '\u0160',
'&sect;': '\u00a7',
'&uml;': '\u0161',
'&copy;': '\u00a9',
'&ordf;': '\u00aa',
'&laquo;': '\u00ab',
'&not;': '\u00ac',
'&shy;': '\u00ad',
'&reg;': '\u00ae',
'&macr;': '\u00af',
'&deg;': '\u00b0',
'&plusmn;': '\u00b1',
'&sup2;': '\u00b2',
'&sup3;': '\u00b3',
'&acute;': '\u017d',
'&micro;': '\u00b5',
'&para;': '\u00b6',
'&middot;': '\u00b7',
'&cedil;': '\u017e',
'&sup1;': '\u00b9',
'&ordm;': '\u00ba',
'&raquo;': '\u00bb',
'&frac14;': '\u0152',
'&frac12;': '\u00bd',
'&frac34;': '\u0178',
'&iquest;': '\u00bf',
'&Agrave;': '\u00c0',
'&Aacute;': '\u00c1',
'&Acirc;': '\u00c2',
'&Atilde;': '\u00c3',
'&Auml;': '\u00c4',
'&Aring;': '\u00c5',
'&AElig;': '\u00c6',
'&Ccedil;': '\u00c7',
'&Egrave;': '\u00c8',
'&Eacute;': '\u00c9',
'&Ecirc;': '\u00ca',
'&Euml;': '\u00cb',
'&Igrave;': '\u00cc',
'&Iacute;': '\u00cd',
'&Icirc;': '\u00ce',
'&Iuml;': '\u00cf',
'&ETH;': '\u00d0',
'&Ntilde;': '\u00d1',
'&Ograve;': '\u00d2',
'&Oacute;': '\u00d3',
'&Ocirc;': '\u00d4',
'&Otilde;': '\u00d5',
'&Ouml;': '\u00d6',
'&times;': '\u00d7',
'&Oslash;': '\u00d8',
'&Ugrave;': '\u00d9',
'&Uacute;': '\u00da',
'&Ucirc;': '\u00db',
'&Uuml;': '\u00dc',
'&Yacute;': '\u00dd',
'&THORN;': '\u00de',
'&szlig;': '\u00df',
'&agrave;': '\u00e0',
'&aacute;': '\u00e1',
'&acirc;': '\u00e2',
'&atilde;': '\u00e3',
'&auml;': '\u00e4',
'&aring;': '\u00e5',
'&aelig;': '\u00e6',
'&ccedil;': '\u00e7',
'&egrave;': '\u00e8',
'&eacute;': '\u00e9',
'&ecirc;': '\u00ea',
'&euml;': '\u00eb',
'&igrave;': '\u00ec',
'&iacute;': '\u00ed',
'&icirc;': '\u00ee',
'&iuml;': '\u00ef',
'&eth;': '\u00f0',
'&ntilde;': '\u00f1',
'&ograve;': '\u00f2',
'&oacute;': '\u00f3',
'&ocirc;': '\u00f4',
'&otilde;': '\u00f5',
'&ouml;': '\u00f6',
'&divide;': '\u00f7',
'&oslash;': '\u00f8',
'&ugrave;': '\u00f9',
'&uacute;': '\u00fa',
'&ucirc;': '\u00fb',
'&uuml;': '\u00fc',
'&yacute;': '\u00fd',
'&thorn;': '\u00fe',
'&yuml;': '\u00ff',
'&quot;': '\u0022',
'&lt;': '\u003c',
'&gt;': '\u003e',
'&apos;': '\u0027',
'&minus;': '\u2212',
'&circ;': '\u02c6',
'&tilde;': '\u02dc',
'&Scaron;': '\u0160',
'&lsaquo;': '\u2039',
'&OElig;': '\u0152',
'&lsquo;': '\u2018',
'&rsquo;': '\u2019',
'&ldquo;': '\u201c',
'&rdquo;': '\u201d',
'&bull;': '\u2022',
'&ndash;': '\u2013',
'&mdash;': '\u2014',
'&trade;': '\u2122',
'&scaron;': '\u0161',
'&rsaquo;': '\u203a',
'&oelig;': '\u0153',
'&Yuml;': '\u0178',
'&fnof;': '\u0192',
'&Alpha;': '\u0391',
'&Beta;': '\u0392',
'&Gamma;': '\u0393',
'&Delta;': '\u0394',
'&Epsilon;': '\u0395',
'&Zeta;': '\u0396',
'&Eta;': '\u0397',
'&Theta;': '\u0398',
'&Iota;': '\u0399',
'&Kappa;': '\u039a',
'&Lambda;': '\u039b',
'&Mu;': '\u039c',
'&Nu;': '\u039d',
'&Xi;': '\u039e',
'&Omicron;': '\u039f',
'&Pi;': '\u03a0',
'&Rho;': '\u03a1',
'&Sigma;': '\u03a3',
'&Tau;': '\u03a4',
'&Upsilon;': '\u03a5',
'&Phi;': '\u03a6',
'&Chi;': '\u03a7',
'&Psi;': '\u03a8',
'&Omega;': '\u03a9',
'&alpha;': '\u03b1',
'&beta;': '\u03b2',
'&gamma;': '\u03b3',
'&delta;': '\u03b4',
'&epsilon;': '\u03b5',
'&zeta;': '\u03b6',
'&eta;': '\u03b7',
'&theta;': '\u03b8',
'&iota;': '\u03b9',
'&kappa;': '\u03ba',
'&lambda;': '\u03bb',
'&mu;': '\u03bc',
'&nu;': '\u03bd',
'&xi;': '\u03be',
'&omicron;': '\u03bf',
'&pi;': '\u03c0',
'&rho;': '\u03c1',
'&sigmaf;': '\u03c2',
'&sigma;': '\u03c3',
'&tau;': '\u03c4',
'&upsilon;': '\u03c5',
'&phi;': '\u03c6',
'&chi;': '\u03c7',
'&psi;': '\u03c8',
'&omega;': '\u03c9',
'&thetasym;': '\u03d1',
'&upsih;': '\u03d2',
'&piv;': '\u03d6',
'&ensp;': '\u2002',
'&emsp;': '\u2003',
'&thinsp;': '\u2009',
'&zwnj;': '\u200c',
'&zwj;': '\u200d',
'&lrm;': '\u200e',
'&rlm;': '\u200f',
'&sbquo;': '\u201a',
'&bdquo;': '\u201e',
'&dagger;': '\u2020',
'&Dagger;': '\u2021',
'&hellip;': '\u2026',
'&permil;': '\u2030',
'&prime;': '\u2032',
'&Prime;': '\u2033',
'&oline;': '\u203e',
'&frasl;': '\u2044',
'&image;': '\u2111',
'&weierp;': '\u2118',
'&real;': '\u211c',
'&alefsym;': '\u2135',
'&larr;': '\u2190',
'&uarr;': '\u2191',
'&rarr;': '\u2192',
'&darr;': '\u2193',
'&harr;': '\u2194',
'&crarr;': '\u21b5',
'&lArr;': '\u21d0',
'&uArr;': '\u21d1',
'&rArr;': '\u21d2',
'&dArr;': '\u21d3',
'&hArr;': '\u21d4',
'&forall;': '\u2200',
'&part;': '\u2202',
'&exist;': '\u2203',
'&empty;': '\u2205',
'&nabla;': '\u2207',
'&isin;': '\u2208',
'&notin;': '\u2209',
'&ni;': '\u220b',
'&prod;': '\u220f',
'&sum;': '\u2211',
'&lowast;': '\u2217',
'&radic;': '\u221a',
'&prop;': '\u221d',
'&infin;': '\u221e',
'&ang;': '\u2220',
'&and;': '\u2227',
'&or;': '\u2228',
'&cap;': '\u2229',
'&cup;': '\u222a',
'&int;': '\u222b',
'&there4;': '\u2234',
'&sim;': '\u223c',
'&cong;': '\u2245',
'&asymp;': '\u2248',
'&ne;': '\u2260',
'&equiv;': '\u2261',
'&le;': '\u2264',
'&ge;': '\u2265',
'&sub;': '\u2282',
'&sup;': '\u2283',
'&nsub;': '\u2284',
'&sube;': '\u2286',
'&supe;': '\u2287',
'&oplus;': '\u2295',
'&otimes;': '\u2297',
'&perp;': '\u22a5',
'&sdot;': '\u22c5',
'&lceil;': '\u2308',
'&rceil;': '\u2309',
'&lfloor;': '\u230a',
'&rfloor;': '\u230b',
'&lang;': '\u2329',
'&rang;': '\u232a',
'&loz;': '\u25ca',
'&spades;': '\u2660',
'&clubs;': '\u2663',
'&hearts;': '\u2665',
'&diams;': '\u2666'
};
exports.decode = function (str) {
if (!~str.indexOf('&')) return str;
//Decode literal entities
for (var i in entities) {
str = str.replace(new RegExp(i, 'g'), entities[i]);
}
//Decode hex entities
str = str.replace(/&#x(0*[0-9a-f]{2,5});?/gi, function (m, code) {
return String.fromCharCode(parseInt(+code, 16));
});
//Decode numeric entities
str = str.replace(/&#([0-9]{2,4});?/gi, function (m, code) {
return String.fromCharCode(+code);
});
str = str.replace(/&amp;/g, '&');
return str;
}
exports.encode = function (str) {
str = str.replace(/&/g, '&amp;');
//IE doesn't accept &apos;
str = str.replace(/'/g, '&#39;');
//Encode literal entities
for (var i in entities) {
str = str.replace(new RegExp(entities[i], 'g'), i);
}
return str;
}

109
node_modules/resanitize/node_modules/validator/lib/filter.js generated vendored Executable file
View File

@@ -0,0 +1,109 @@
var entities = require('./entities');
var xss = require('./xss');
var Filter = exports.Filter = function() {}
var whitespace = '\\r\\n\\t\\s';
Filter.prototype.modify = function(str) {
this.str = str;
}
Filter.prototype.wrap = function (str) {
return str;
}
Filter.prototype.value = function () {
return this.str;
}
Filter.prototype.chain = function () {
this.wrap = function () { return this };
return this;
}
//Create some aliases - may help code readability
Filter.prototype.convert = Filter.prototype.sanitize = function(str) {
this.str = str == null ? '' : str + '';
return this;
}
Filter.prototype.xss = function(is_image) {
this.modify(xss.clean(this.str, is_image));
return this.wrap(this.str);
}
Filter.prototype.entityDecode = function() {
this.modify(entities.decode(this.str));
return this.wrap(this.str);
}
Filter.prototype.entityEncode = function() {
this.modify(entities.encode(this.str));
return this.wrap(this.str);
}
Filter.prototype.ltrim = function(chars) {
chars = chars || whitespace;
this.modify(this.str.replace(new RegExp('^['+chars+']+', 'g'), ''));
return this.wrap(this.str);
}
Filter.prototype.rtrim = function(chars) {
chars = chars || whitespace;
this.modify(this.str.replace(new RegExp('['+chars+']+$', 'g'), ''));
return this.wrap(this.str);
}
Filter.prototype.trim = function(chars) {
chars = chars || whitespace;
this.modify(this.str.replace(new RegExp('^['+chars+']+|['+chars+']+$', 'g'), ''));
return this.wrap(this.str);
}
Filter.prototype.escape = function() {
this.modify(this.str.replace(/&/g, '&amp;')
.replace(/"/g, '&quot;')
.replace(/</g, '&lt;')
.replace(/>/g, '&gt;'));
return this.wrap(this.str);
};
Filter.prototype.ifNull = function(replace) {
if (!this.str || this.str === '') {
this.modify(replace);
}
return this.wrap(this.str);
}
Filter.prototype.toFloat = function() {
this.modify(parseFloat(this.str));
return this.wrap(this.str);
}
Filter.prototype.toInt = function(radix) {
this.modify(parseInt(this.str, radix || 10));
return this.wrap(this.str);
}
//Any strings with length > 0 (except for '0' and 'false') are considered true,
//all other strings are false
Filter.prototype.toBoolean = function() {
if (!this.str || this.str == '0' || this.str == 'false' || this.str == '') {
this.modify(false);
} else {
this.modify(true);
}
return this.wrap(this.str);
}
//String must be equal to '1' or 'true' to be considered true, all other strings
//are false
Filter.prototype.toBooleanStrict = function() {
if (this.str == '1' || this.str == 'true') {
this.modify(true);
} else {
this.modify(false);
}
return this.wrap(this.str);
}

20
node_modules/resanitize/node_modules/validator/lib/index.js generated vendored Executable file
View File

@@ -0,0 +1,20 @@
var node_validator = require('./validator');
exports.Validator = node_validator.Validator;
exports.ValidatorError = node_validator.ValidatorError;
exports.Filter = require('./filter').Filter;
exports.validators = require('./validators');
exports.defaultError = require('./defaultError');
exports.entities = require('./entities');
//Quick access methods
exports.sanitize = exports.convert = function(str) {
var filter = new exports.Filter();
return filter.sanitize(str);
}
exports.check = exports.validate = exports.assert = function(str, fail_msg) {
var validator = new exports.Validator();
return validator.check(str, fail_msg);
}

View File

@@ -0,0 +1,76 @@
var util = require('util');
var validators = require('./validators');
exports.defaultError = require('./defaultError');
var ValidatorError = exports.ValidatorError = function(msg) {
Error.captureStackTrace(this, this);
this.name = 'ValidatorError';
this.message = msg;
};
util.inherits(ValidatorError, Error);
var Validator = exports.Validator = function(options) {
options = options || {};
this.options = options;
this.options.messageBuilder = this.options.messageBuilder || function (msg, args) {
if (typeof msg === 'string') {
args.forEach(function(arg, i) { msg = msg.replace('%'+i, arg); });
}
return msg;
};
};
Validator.prototype.error = function (msg) {
throw new ValidatorError(msg);
};
Validator.prototype.check = function(str, fail_msg) {
if (typeof str === 'object' && str !== null && str.toString) {
str = str.toString();
}
this.str = (str == null || (isNaN(str) && str.length == undefined)) ? '' : str;
this.str += '';
// This is a key, value pair of error messages to use
if (typeof fail_msg === 'object') {
this.errorDictionary = fail_msg;
this.msg = null
}
else {
this.errorDictionary = {};
this.msg = fail_msg;
}
this._errors = this._errors || [];
return this;
}
for (var key in validators) {
if (validators.hasOwnProperty(key)) {
(function (key) {
Validator.prototype[key] = function() {
var args = Array.prototype.slice.call(arguments);
args.unshift(this.str);
if(!validators[key].apply(this, args)) {
var msg = exports.defaultError[key];
if (key in this.errorDictionary) {
msg = this.errorDictionary[key];
} else if (this.msg !== null && typeof this.msg !== 'undefined') {
msg = this.msg;
}
msg = this.options.messageBuilder(msg, args);
return this.error(msg);
}
return this;
};
})(key);
}
}
//Create some aliases - may help code readability
Validator.prototype.validate = Validator.prototype.check;
Validator.prototype.assert = Validator.prototype.check;
Validator.prototype.isFloat = Validator.prototype.isDecimal;
Validator.prototype.is = Validator.prototype.regex;
Validator.prototype.not = Validator.prototype.notRegex;

View File

@@ -0,0 +1,240 @@
// Helper function to avoid duplication of code
function toDateTime(date) {
if (date instanceof Date) {
return date;
}
var intDate = Date.parse(date);
if (isNaN(intDate)) {
return null;
}
return new Date(intDate);
}
// Convert to date without the time component
function toDate(date) {
if (!(date instanceof Date)) {
date = toDateTime(date);
}
if (!date) {
return null;
}
return date;
}
var validators = module.exports = {
isEmail: function(str) {
return str.match(/^(?:[\w\!\#\$\%\&\'\*\+\-\/\=\?\^\`\{\|\}\~]+\.)*[\w\!\#\$\%\&\'\*\+\-\/\=\?\^\`\{\|\}\~]+@(?:(?:(?:[a-zA-Z0-9](?:[a-zA-Z0-9\-](?!\.)){0,61}[a-zA-Z0-9]?\.)+[a-zA-Z0-9](?:[a-zA-Z0-9\-](?!$)){0,61}[a-zA-Z0-9]?)|(?:\[(?:(?:[01]?\d{1,2}|2[0-4]\d|25[0-5])\.){3}(?:[01]?\d{1,2}|2[0-4]\d|25[0-5])\]))$/);
},
isUrl: function(str) {
//A modified version of the validator from @diegoperini / https://gist.github.com/729294
return str.length < 2083 && str.match(/^(?!mailto:)(?:(?:https?|ftp):\/\/)?(?:\S+(?::\S*)?@)?(?:(?:(?:[1-9]\d?|1\d\d|2[01]\d|22[0-3])(?:\.(?:1?\d{1,2}|2[0-4]\d|25[0-5])){2}(?:\.(?:[0-9]\d?|1\d\d|2[0-4]\d|25[0-4]))|(?:(?:[a-z\u00a1-\uffff0-9]+-?)*[a-z\u00a1-\uffff0-9]+)(?:\.(?:[a-z\u00a1-\uffff0-9]+-?)*[a-z\u00a1-\uffff0-9]+)*(?:\.(?:[a-z\u00a1-\uffff]{2,})))|localhost)(?::\d{2,5})?(?:\/[^\s]*)?$/i);
},
//node-js-core
isIP : function(str) {
if (validators.isIPv4(str)) {
return 4;
} else if (validators.isIPv6(str)) {
return 6;
} else {
return 0;
}
},
//node-js-core
isIPv4 : function(str) {
if (/^(\d?\d?\d)\.(\d?\d?\d)\.(\d?\d?\d)\.(\d?\d?\d)$/.test(str)) {
var parts = str.split('.').sort();
// no need to check for < 0 as regex won't match in that case
if (parts[3] > 255) {
return false;
}
return true;
}
return false;
},
//node-js-core
isIPv6 : function(str) {
if (/^::|^::1|^([a-fA-F0-9]{1,4}::?){1,7}([a-fA-F0-9]{1,4})$/.test(str)) {
return true;
}
return false;
},
isIPNet: function(str) {
return validators.isIP(str) !== 0;
},
isAlpha: function(str) {
return str.match(/^[a-zA-Z]+$/);
},
isAlphanumeric: function(str) {
return str.match(/^[a-zA-Z0-9]+$/);
},
isNumeric: function(str) {
return str.match(/^-?[0-9]+$/);
},
isHexadecimal: function(str) {
return str.match(/^[0-9a-fA-F]+$/);
},
isHexColor: function(str) {
return str.match(/^#?([0-9a-fA-F]{3}|[0-9a-fA-F]{6})$/);
},
isLowercase: function(str) {
return str === str.toLowerCase();
},
isUppercase: function(str) {
return str === str.toUpperCase();
},
isInt: function(str) {
return str.match(/^(?:-?(?:0|[1-9][0-9]*))$/);
},
isDecimal: function(str) {
return str !== '' && str.match(/^(?:-?(?:[0-9]+))?(?:\.[0-9]*)?(?:[eE][\+\-]?(?:[0-9]+))?$/);
},
isFloat: function(str) {
return validators.isDecimal(str);
},
isDivisibleBy: function(str, n) {
return (parseFloat(str) % parseInt(n, 10)) === 0;
},
notNull: function(str) {
return str !== '';
},
isNull: function(str) {
return str === '';
},
notEmpty: function(str) {
return !str.match(/^[\s\t\r\n]*$/);
},
equals: function(a, b) {
return a == b;
},
contains: function(str, elem) {
return str.indexOf(elem) >= 0 && !!elem;
},
notContains: function(str, elem) {
return !validators.contains(str, elem);
},
regex: function(str, pattern, modifiers) {
str += '';
if (Object.prototype.toString.call(pattern).slice(8, -1) !== 'RegExp') {
pattern = new RegExp(pattern, modifiers);
}
return str.match(pattern);
},
is: function(str, pattern, modifiers) {
return validators.regex(str, pattern, modifiers);
},
notRegex: function(str, pattern, modifiers) {
return !validators.regex(str, pattern, modifiers);
},
not: function(str, pattern, modifiers) {
return validators.notRegex(str, pattern, modifiers);
},
len: function(str, min, max) {
return str.length >= min && (max === undefined || str.length <= max);
},
//Thanks to github.com/sreuter for the idea.
isUUID: function(str, version) {
var pattern;
if (version == 3 || version == 'v3') {
pattern = /^[0-9A-F]{8}-[0-9A-F]{4}-3[0-9A-F]{3}-[0-9A-F]{4}-[0-9A-F]{12}$/i;
} else if (version == 4 || version == 'v4') {
pattern = /^[0-9A-F]{8}-[0-9A-F]{4}-4[0-9A-F]{3}-[89AB][0-9A-F]{3}-[0-9A-F]{12}$/i;
} else if (version == 5 || version == 'v5') {
pattern = /^[0-9A-F]{8}-[0-9A-F]{4}-5[0-9A-F]{3}-[89AB][0-9A-F]{3}-[0-9A-F]{12}$/i;
} else {
pattern = /^[0-9A-F]{8}-[0-9A-F]{4}-[0-9A-F]{4}-[0-9A-F]{4}-[0-9A-F]{12}$/i;
}
return pattern.test(str);
},
isUUIDv3: function(str) {
return validators.isUUID(str, 3);
},
isUUIDv4: function(str) {
return validators.isUUID(str, 4);
},
isUUIDv5: function(str) {
return validators.isUUID(str, 5);
},
isDate: function(str) {
var intDate = Date.parse(str);
return !isNaN(intDate);
},
isAfter: function(str, date) {
date = date || new Date();
var origDate = toDate(str);
var compDate = toDate(date);
return !(origDate && compDate && origDate <= compDate);
},
isBefore: function(str, date) {
date = date || new Date();
var origDate = toDate(str);
var compDate = toDate(date);
return !(origDate && compDate && origDate >= compDate);
},
isIn: function(str, options) {
if (!options || typeof options.indexOf !== 'function') {
return false;
}
if (Array.isArray(options)) {
options = options.map(String);
}
return options.indexOf(str) >= 0;
},
notIn: function(str, options) {
if (!options || typeof options.indexOf !== 'function') {
return false;
}
if (Array.isArray(options)) {
options = options.map(String);
}
return options.indexOf(str) < 0;
},
min: function(str, val) {
var number = parseFloat(str);
return isNaN(number) || number >= val;
},
max: function(str, val) {
var number = parseFloat(str);
return isNaN(number) || number <= val;
},
//Will work against Visa, MasterCard, American Express, Discover, Diners Club, and JCB card numbering formats
isCreditCard: function(str) {
//remove all dashes, spaces, etc.
var sanitized = str.replace(/[^0-9]+/g, '');
if (sanitized.match(/^(?:4[0-9]{12}(?:[0-9]{3})?|5[1-5][0-9]{14}|6(?:011|5[0-9][0-9])[0-9]{12}|3[47][0-9]{13}|3(?:0[0-5]|[68][0-9])[0-9]{11}|(?:2131|1800|35\d{3})\d{11})$/) === null) {
return null;
}
// Doing Luhn check
var sum = 0;
var digit;
var tmpNum;
var shouldDouble = false;
for (var i = sanitized.length - 1; i >= 0; i--) {
digit = sanitized.substring(i, (i + 1));
tmpNum = parseInt(digit, 10);
if (shouldDouble) {
tmpNum *= 2;
if (tmpNum >= 10) {
sum += ((tmpNum % 10) + 1);
}
else {
sum += tmpNum;
}
}
else {
sum += tmpNum;
}
if (shouldDouble) {
shouldDouble = false;
}
else {
shouldDouble = true;
}
}
if ((sum % 10) === 0) {
return sanitized;
} else {
return null;
}
}
};

228
node_modules/resanitize/node_modules/validator/lib/xss.js generated vendored Executable file
View File

@@ -0,0 +1,228 @@
//This module is adapted from the CodeIgniter framework
//The license is available at http://codeigniter.com/
var html_entity_decode = require('./entities').decode;
var never_allowed_str = {
'document.cookie': '[removed]',
'document.write': '[removed]',
'.parentNode': '[removed]',
'.innerHTML': '[removed]',
'window.location': '[removed]',
'-moz-binding': '[removed]',
'<!--': '&lt;!--',
'-->': '--&gt;',
'(<!\\[CDATA\\[)': '&lt;![CDATA[',
'<comment>': '&lt;comment&gt;'
};
var never_allowed_regex = {
'javascript\\s*:': '[removed]',
'expression\\s*(\\(|&#40;)': '[removed]',
'vbscript\\s*:': '[removed]',
'Redirect\\s+302': '[removed]',
"([\"'])?data\\s*:[^\\1]*?base64[^\\1]*?,[^\\1]*?\\1?": '[removed]'
};
var non_displayables = [
/%0[0-8bcef]/g, // url encoded 00-08, 11, 12, 14, 15
/%1[0-9a-f]/g, // url encoded 16-31
/[\x00-\x08]/g, // 00-08
/\x0b/g, /\x0c/g, // 11,12
/[\x0e-\x1f]/g // 14-31
];
var compact_words = [
'javascript', 'expression', 'vbscript',
'script', 'base64', 'applet', 'alert',
'document', 'write', 'cookie', 'window'
];
exports.clean = function(str, is_image) {
//Remove invisible characters
str = remove_invisible_characters(str);
//Protect query string variables in URLs => 901119URL5918AMP18930PROTECT8198
var hash;
do {
// ensure str does not contain hash before inserting it
hash = xss_hash();
} while(str.indexOf(hash) >= 0)
str = str.replace(/\&([a-z\_0-9\-]+)\=([a-z\_0-9\-]+)/ig, hash + '$1=$2');
//Validate standard character entities. Add a semicolon if missing. We do this to enable
//the conversion of entities to ASCII later.
str = str.replace(/(&#?[0-9a-z]{2,})([\x00-\x20])*;?/ig, '$1;$2');
//Validate UTF16 two byte encoding (x00) - just as above, adds a semicolon if missing.
str = str.replace(/(&#x?)([0-9A-F]+);?/ig, '$1$2;');
//Un-protect query string variables
str = str.replace(new RegExp(hash, 'g'), '&');
//Decode just in case stuff like this is submitted:
//<a href="http://%77%77%77%2E%67%6F%6F%67%6C%65%2E%63%6F%6D">Google</a>
try{
str = decodeURIComponent(str);
}
catch(error){
// str was not actually URI-encoded
}
//Convert character entities to ASCII - this permits our tests below to work reliably.
//We only convert entities that are within tags since these are the ones that will pose security problems.
str = str.replace(/[a-z]+=([\'\"]).*?\1/gi, function(m, match) {
return m.replace(match, convert_attribute(match));
});
str = str.replace(/<\w+.*/gi, function(m) {
return m.replace(m, html_entity_decode(m));
});
//Remove invisible characters again
str = remove_invisible_characters(str);
//Convert tabs to spaces
str = str.replace('\t', ' ');
//Captured the converted string for later comparison
var converted_string = str;
//Remove strings that are never allowed
for (var i in never_allowed_str) {
str = str.replace(new RegExp(i, "gi"), never_allowed_str[i]);
}
//Remove regex patterns that are never allowed
for (var i in never_allowed_regex) {
str = str.replace(new RegExp(i, 'gi'), never_allowed_regex[i]);
}
//Compact any exploded words like: j a v a s c r i p t
// We only want to do this when it is followed by a non-word character
for (var i = 0, l = compact_words.length; i < l; i++) {
var spacified = compact_words[i].split('').join('\\s*')+'\\s*';
str = str.replace(new RegExp('('+spacified+')(\\W)', 'ig'), function(m, compat, after) {
return compat.replace(/\s+/g, '') + after;
});
}
//Remove disallowed Javascript in links or img tags
do {
var original = str;
if (str.match(/<a/i)) {
str = str.replace(/<a\s+([^>]*?)(>|$)/gi, function(m, attributes, end_tag) {
var filtered_attributes = filter_attributes(attributes.replace('<','').replace('>',''));
filtered_attributes = filtered_attributes.replace(/href=.*?(?:alert\(|alert&#40;|javascript:|livescript:|mocha:|charset=|window\.|document\.|\.cookie|<script|<xss|data\s*:)/gi, '');
return m.replace(attributes, filtered_attributes);
});
}
if (str.match(/<img/i)) {
str = str.replace(/<img\s+([^>]*?)(\s?\/?>|$)/gi, function(m, attributes, end_tag) {
var filtered_attributes = filter_attributes(attributes.replace('<','').replace('>',''));
filtered_attributes = filtered_attributes.replace(/src=.*?(?:alert\(|alert&#40;|javascript:|livescript:|mocha:|charset=|window\.|document\.|\.cookie|<script|<xss|base64\s*,)/gi, '');
return m.replace(attributes, filtered_attributes);
});
}
if (str.match(/script/i) || str.match(/xss/i)) {
str = str.replace(/<(\/*)(script|xss)(.*?)\>/gi, '[removed]');
}
} while(original !== str);
// Remove Evil HTML Attributes (like event handlers and style)
var event_handlers = ['\\bon\\w*', '\\bstyle', '\\bformaction'];
//Adobe Photoshop puts XML metadata into JFIF images, including namespacing,
//so we have to allow this for images
if (!is_image) {
event_handlers.push('xmlns');
}
do {
var attribs = [];
var count = 0;
attribs = attribs.concat(str.match(new RegExp("("+event_handlers.join('|')+")\\s*=\\s*(\\x22|\\x27)([^\\2]*?)(\\2)", 'ig')));
attribs = attribs.concat(str.match(new RegExp("("+event_handlers.join('|')+")\\s*=\\s*([^\\s>]*)", 'ig')));
attribs = attribs.filter(function(element) { return element !== null; });
if (attribs.length > 0) {
for (var i = 0; i < attribs.length; ++i) {
attribs[i] = attribs[i].replace(new RegExp('[.\\\\+*?\\[\\^\\]$(){}=!<>|:\\-]', 'g'), '\\$&')
}
str = str.replace(new RegExp("(<?)(\/?[^><]+?)([^A-Za-z<>\\-])(.*?)("+attribs.join('|')+")(.*?)([\\s><]?)([><]*)", 'i'), function(m, a, b, c, d, e, f, g, h) {
++count;
return a + b + ' ' + d + f + g + h;
});
}
} while (count > 0);
//Sanitize naughty HTML elements
//If a tag containing any of the words in the list
//below is found, the tag gets converted to entities.
//So this: <blink>
//Becomes: &lt;blink&gt;
var naughty = 'alert|applet|audio|basefont|base|behavior|bgsound|blink|body|embed|expression|form|frameset|frame|head|html|ilayer|iframe|input|isindex|layer|link|meta|object|plaintext|style|script|textarea|title|video|xml|xss';
str = str.replace(new RegExp('<(/*\\s*)('+naughty+')([^><]*)([><]*)', 'gi'), function(m, a, b, c, d) {
return '&lt;' + a + b + c + d.replace('>','&gt;').replace('<','&lt;');
});
//Sanitize naughty scripting elements Similar to above, only instead of looking for
//tags it looks for PHP and JavaScript commands that are disallowed. Rather than removing the
//code, it simply converts the parenthesis to entities rendering the code un-executable.
//For example: eval('some code')
//Becomes: eval&#40;'some code'&#41;
str = str.replace(/(alert|cmd|passthru|eval|exec|expression|system|fopen|fsockopen|file|file_get_contents|readfile|unlink)(\s*)\((.*?)\)/gi, '$1$2&#40;$3&#41;');
//This adds a bit of extra precaution in case something got through the above filters
for (var i in never_allowed_str) {
str = str.replace(new RegExp(i, "gi"), never_allowed_str[i]);
}
for (var i in never_allowed_regex) {
str = str.replace(new RegExp(i, 'gi'), never_allowed_regex[i]);
}
//Images are handled in a special way
if (is_image && str !== converted_string) {
throw new Error('Image may contain XSS');
}
return str;
}
function remove_invisible_characters(str) {
for (var i = 0, l = non_displayables.length; i < l; i++) {
str = str.replace(non_displayables[i], '');
}
return str;
}
function xss_hash() {
var str = '', num = 10;
while (num--) str += String.fromCharCode(Math.random() * 25 | 97);
return str;
}
function convert_attribute(str) {
return str.replace('>','&gt;').replace('<','&lt;').replace('\\','\\\\');
}
function filter_attributes(str) {
var result = "";
var match = str.match(/\s*[a-z-]+\s*=\s*(\x22|\x27)([^\1]*?)\1/ig);
if (match) {
for (var i = 0; i < match.length; ++i) {
result += match[i].replace(/\*.*?\*/g, '');
}
}
return result;
}

View File

@@ -0,0 +1,78 @@
{
"name": "validator",
"description": "Data validation, filtering and sanitization for node.js",
"version": "1.5.1",
"homepage": "http://github.com/chriso/node-validator",
"keywords": [
"validator",
"validation",
"assert",
"params",
"sanitization",
"xss",
"entities",
"sanitize",
"sanitisation",
"input"
],
"author": {
"name": "Chris O'Hara",
"email": "cohara87@gmail.com"
},
"main": "./lib",
"directories": {
"lib": "./lib"
},
"bugs": {
"url": "http://github.com/chriso/node-validator/issues"
},
"repository": {
"type": "git",
"url": "http://github.com/chriso/node-validator.git"
},
"contributors": [
{
"name": "PING"
},
{
"name": "Dan VerWeire"
},
{
"name": "Branko Vukelic"
},
{
"name": "Mark Engel"
}
],
"scripts": {
"test": "node test/run.js"
},
"engines": {
"node": ">=0.2.2"
},
"licenses": [
{
"type": "MIT",
"url": "http://github.com/chriso/node-validator/raw/master/LICENSE"
}
],
"_id": "validator@1.5.1",
"dist": {
"shasum": "7ab356cbbcbbb000ab85c43b8cda12621b1344c0",
"tarball": "http://registry.npmjs.org/validator/-/validator-1.5.1.tgz"
},
"_from": "validator@>=1.5.1 <1.6.0",
"_npmVersion": "1.3.8",
"_npmUser": {
"name": "cohara87",
"email": "cohara87@gmail.com"
},
"maintainers": [
{
"name": "cohara87",
"email": "cohara87@gmail.com"
}
],
"_shasum": "7ab356cbbcbbb000ab85c43b8cda12621b1344c0",
"_resolved": "https://registry.npmjs.org/validator/-/validator-1.5.1.tgz"
}

View File

@@ -0,0 +1,5 @@
v = require('./');
//console.log(v.sanitize('<scrRedirecRedirect 302t 302ipt type="text/javascript">prompt(1);</scrRedirecRedirect 302t 302ipt>').xss());
v.check('foo', 'The message needs to be between %1 and %2 characters long (you passed "%0")').len(4, 6);

View File

@@ -0,0 +1,5 @@
// tests exports of built validator.js file
var node_validator = require('../validator.js');
module.exports = require('./exports.test.js')(node_validator);

View File

@@ -0,0 +1,59 @@
// not to be run on its own...
// to be required in module that already has node_validator defined and passed as param to require
// that way it can be used to test the built versions too when they are compiled
var assert = require('assert');
module.exports = function(node_validator) {
return {
'test #Validator is exported when built': function () {
assert.equal(typeof node_validator.Validator, 'function');
},
'test #ValidatorError is exported when built': function () {
assert.equal(typeof node_validator.ValidatorError, 'function');
},
'test #Filter is exported when built': function () {
assert.equal(typeof node_validator.Filter, 'function');
},
'test #validators is exported when built': function () {
assert.equal(typeof node_validator.validators, 'object');
},
'test #defaultError is exported when built': function () {
assert.equal(typeof node_validator.defaultError, 'object');
},
'test #entities is exported when built': function () {
assert.equal(typeof node_validator.entities, 'object');
},
'test #sanitize is exported when built': function () {
assert.equal(typeof node_validator.sanitize, 'function');
},
'test #convert alias for #sanitize is exported when built': function () {
assert.equal(typeof node_validator.convert, 'function');
assert.equal(node_validator.convert, node_validator.sanitize);
},
'test #check is exported when built': function () {
assert.equal(typeof node_validator.check, 'function');
},
'test #validate alias for #check is exported when built': function () {
assert.equal(typeof node_validator.validate, 'function');
assert.equal(node_validator.validate, node_validator.check);
},
'test #assert alias for #check is exported when built': function () {
assert.equal(typeof node_validator.assert, 'function');
assert.equal(node_validator.assert, node_validator.check);
}
}
};

View File

@@ -0,0 +1,172 @@
var node_validator = require('../lib'),
Filter = new node_validator.Filter(),
assert = require('assert');
module.exports = {
'test #ifNull()': function () {
//Make sure sanitize returns the new string
assert.equal(5, Filter.sanitize('').ifNull(5));
assert.equal('abc', Filter.sanitize().ifNull('abc'));
//Modify Filter.modify() to automatically replace a var with the sanitized version
var param = '';
Filter.modify = function(str) {
this.str = str;
param = str;
}
Filter.sanitize(param).ifNull('foobar');
assert.equal('foobar', param);
},
'test #toBoolean()': function () {
assert.equal(true, Filter.sanitize('1').toBoolean());
assert.equal(true, Filter.sanitize('true').toBoolean());
assert.equal(true, Filter.sanitize('foobar').toBoolean());
assert.equal(true, Filter.sanitize(5).toBoolean());
assert.equal(true, Filter.sanitize(' ').toBoolean());
assert.equal(false, Filter.sanitize('0').toBoolean());
assert.equal(false, Filter.sanitize('false').toBoolean());
assert.equal(false, Filter.sanitize('').toBoolean());
assert.equal(false, Filter.sanitize('false').toBoolean());
},
'test #toBooleanStrict()': function () {
assert.equal(true, Filter.sanitize('1').toBooleanStrict());
assert.equal(true, Filter.sanitize('true').toBooleanStrict());
assert.equal(false, Filter.sanitize('foobar').toBooleanStrict());
assert.equal(false, Filter.sanitize(5).toBooleanStrict());
assert.equal(false, Filter.sanitize(' ').toBooleanStrict());
assert.equal(false, Filter.sanitize('0').toBooleanStrict());
assert.equal(false, Filter.sanitize('false').toBooleanStrict());
assert.equal(false, Filter.sanitize('').toBooleanStrict());
assert.equal(false, Filter.sanitize('false').toBooleanStrict());
},
'test #trim()': function () {
//Test trim() with spaces
assert.equal('abc', Filter.sanitize(' abc').trim());
assert.equal('abc', Filter.sanitize('abc ').trim());
assert.equal('abc', Filter.sanitize(' abc ').trim());
//Test trim() with \t
assert.equal('abc', Filter.sanitize(' abc').trim());
assert.equal('abc', Filter.sanitize('abc ').trim());
assert.equal('abc', Filter.sanitize(' abc ').trim());
//Test trim() with a mixture of \t, \s, \r and \n
assert.equal('abc', Filter.sanitize(' \r\n abc\r\n ').trim());
//Test trim() with custom chars
assert.equal('2', Filter.sanitize('000020000').trim('0'));
assert.equal('202', Filter.sanitize('01000202100101').trim('01'));
},
'test #ltrim()': function () {
//Test ltrim() with spaces
assert.equal('abc', Filter.sanitize(' abc').ltrim());
assert.equal('abc ', Filter.sanitize(' abc ').ltrim());
//Test ltrim() with \t
assert.equal('abc', Filter.sanitize(' abc').ltrim());
assert.equal('abc ', Filter.sanitize(' abc ').ltrim());
//Test ltrim() with a mixture of \t, \s, \r and \n
assert.equal('abc\r\n', Filter.sanitize(' \r\n abc\r\n').ltrim());
//Test ltrim() with custom chars
assert.equal('20', Filter.sanitize('000020').ltrim('0'));
assert.equal('201', Filter.sanitize('010100201').ltrim('01'));
},
'test #rtrim()': function () {
//Test rtrim() with spaces
assert.equal(' abc', Filter.sanitize(' abc ').rtrim());
assert.equal('abc', Filter.sanitize('abc ').rtrim());
//Test rtrim() with \t
assert.equal(' abc', Filter.sanitize(' abc').rtrim());
assert.equal('abc', Filter.sanitize('abc ').rtrim());
//Test rtrim() with a mixture of \t, \s, \r and \n
assert.equal(' \r\n abc', Filter.sanitize(' \r\n abc\r\n ').rtrim());
//Test rtrim() with custom chars
assert.equal('02', Filter.sanitize('02000').rtrim('0'));
assert.equal('012', Filter.sanitize('01201001').rtrim('01'));
},
'test #toInt()': function () {
assert.ok(3 === Filter.sanitize('3').toInt());
assert.ok(255 === Filter.sanitize('ff').toInt(16));
assert.ok(3 === Filter.sanitize(' 3 ').toInt());
},
'test #toFloat()': function () {
assert.ok(3 === Filter.sanitize('3.').toFloat());
assert.ok(3 === Filter.sanitize(' 3 ').toFloat());
assert.ok(0 === Filter.sanitize('.0').toFloat());
assert.ok(13.13 === Filter.sanitize('13.13').toFloat());
},
'test #entityDecode()': function () {
assert.equal('&', Filter.sanitize('&amp;').entityDecode());
assert.equal('&&', Filter.sanitize('&amp;&amp;').entityDecode());
assert.equal('""', Filter.sanitize('&quot;&quot;').entityDecode());
assert.equal('€', Filter.sanitize('&euro;').entityDecode());
assert.equal("'", Filter.sanitize("&#39;").entityDecode());
assert.equal("'", Filter.sanitize("&apos;").entityDecode());
assert.equal('œ', Filter.sanitize('&oelig;').entityDecode());
assert.equal('½', Filter.sanitize('&frac12;').entityDecode());
},
'test #entityEncode()': function () {
assert.equal('&amp;', Filter.sanitize('&').entityEncode());
assert.equal('&amp;&amp;', Filter.sanitize('&&').entityEncode());
assert.equal('&#39;', Filter.sanitize("'").entityEncode());
assert.equal('&quot;&quot;', Filter.sanitize('""').entityEncode());
assert.equal('&euro;', Filter.sanitize('€').entityEncode());
assert.equal('&oelig;', Filter.sanitize('œ').entityEncode());
assert.equal('&frac12;', Filter.sanitize('½').entityEncode());
},
'test #xss()': function () {
//Need more tests!
assert.equal('[removed] foobar', Filter.sanitize('javascript : foobar').xss());
assert.equal('[removed] foobar', Filter.sanitize('j a vasc ri pt: foobar').xss());
assert.equal('<a >some text</a>', Filter.sanitize('<a href="javascript:alert(\'xss\')">some text</a>').xss());
assert.equal('<s <> <s >This is a test</s>', Filter.sanitize('<s <onmouseover="alert(1)"> <s onmouseover="alert(1)">This is a test</s>').xss());
assert.equal('<a >">test</a>', Filter.sanitize('<a href="javascriptJ a V a S c R iPt::alert(1)" "<s>">test</a>').xss());
assert.equal('<div ><h1>You have won</h1>Please click the link and enter your login details: <a href="http://example.com/">http://good.com</a></div>', Filter.sanitize('<div style="z-index: 9999999; background-color: green; width: 100%; height: 100%"><h1>You have won</h1>Please click the link and enter your login details: <a href="http://example.com/">http://good.com</a></div>').xss());
assert.equal('<scrRedirec[removed]t 302ipt type="text/javascript">prompt(1);</scrRedirec[removed]t 302ipt>', Filter.sanitize('<scrRedirecRedirect 302t 302ipt type="text/javascript">prompt(1);</scrRedirecRedirect 302t 302ipt>').xss());
assert.equal('<img src="a" ', Filter.sanitize('<img src="a" onerror=\'eval(atob("cHJvbXB0KDEpOw=="))\'').xss());
// Source: http://blog.kotowicz.net/2012/07/codeigniter-210-xssclean-cross-site.html
assert.equal('<img src=">" >', Filter.sanitize('<img/src=">" onerror=alert(1)>').xss());
assert.equal('<button a=">" autofocus ></button>', Filter.sanitize('<button/a=">" autofocus onfocus=alert&#40;1&#40;></button>').xss());
assert.equal('<button a=">" autofocus >', Filter.sanitize('<button a=">" autofocus onfocus=alert&#40;1&#40;>').xss());
assert.equal('<a target="_blank">clickme in firefox</a>', Filter.sanitize('<a target="_blank" href="data:text/html;BASE64youdummy,PHNjcmlwdD5hbGVydCh3aW5kb3cub3BlbmVyLmRvY3VtZW50LmRvY3VtZW50RWxlbWVudC5pbm5lckhUTUwpPC9zY3JpcHQ+">clickme in firefox</a>').xss());
assert.equal('<a/\'\'\' target="_blank" href=[removed]PHNjcmlwdD5hbGVydChvcGVuZXIuZG9jdW1lbnQuYm9keS5pbm5lckhUTUwpPC9zY3JpcHQ+>firefox11</a>', Filter.sanitize('<a/\'\'\' target="_blank" href=data:text/html;;base64,PHNjcmlwdD5hbGVydChvcGVuZXIuZG9jdW1lbnQuYm9keS5pbm5lckhUTUwpPC9zY3JpcHQ+>firefox11</a>').xss());
var url = 'http://www.example.com/test.php?a=b&b=c&c=d';
assert.equal(url, Filter.sanitize(url).xss());
},
'test chaining': function () {
assert.equal('&amp;amp;amp;', Filter.sanitize('&').chain().entityEncode().entityEncode().entityEncode().value());
//Return the default behaviour
Filter.wrap = function (str) {
return str;
}
},
'test #escape': function () {
assert.equal('&amp;&lt;&quot;&gt;', Filter.sanitize('&<">').escape());
}
}

View File

@@ -0,0 +1,3 @@
var node_validator = require('../lib/index.js');
module.exports = require('./exports.test.js')(node_validator);

View File

@@ -0,0 +1,95 @@
var util = require('util')
Validator = require('../lib').Validator,
assert = require('assert');
Validator.prototype.error = function (msg) {
this._errors.push(msg);
return this;
}
Validator.prototype.getErrors = function () {
return this._errors;
}
var testData = {
number: 'ff'
}
module.exports = {
'test: multiple custom messages': function () {
var v = new Validator();
v.check(testData.number, {
isNumeric: 'testData.number should be a real number',
contains: 'testData.number should contain a 0'
}).isNumeric().contains('0');
errors = v.getErrors();
assert.equal(errors.length, 2);
assert.equal(errors[0], 'testData.number should be a real number');
assert.equal(errors[1], 'testData.number should contain a 0');
},
'test: one custom message, one default': function() {
var v = new Validator();
v.check(testData.number, {
isNumeric: 'testData.number should be a real number'
}).isNumeric().contains('0');
errors = v.getErrors();
assert.equal(errors.length, 2);
assert.equal(errors[0], 'testData.number should be a real number');
assert.equal(errors[1], 'Invalid characters');
},
'test: global error message': function() {
var v = new Validator();
v.check(testData.number, 'The value you entered is not valid').isNumeric().contains('0');
errors = v.getErrors();
assert.equal(errors.length, 2);
assert.equal(errors[0], 'The value you entered is not valid');
assert.equal(errors[1], 'The value you entered is not valid');
},
'test: custom message for a validation that is not used': function() {
var v = new Validator();
v.check(testData.number, {
isNumeric: 'testData.number should be a real number',
isInt: 'testData.number should be an Integer'
}).isNumeric().contains('0');
errors = v.getErrors();
assert.equal(errors.length, 2);
assert.equal(errors[0], 'testData.number should be a real number');
assert.equal(errors[1], 'Invalid characters');
},
'test: custom messages with parameters': function () {
var v = new Validator();
v.check(testData.number, {
isNumeric: 'testData.number should be a real number',
contains: 'testData.number %0 should contain a %1'
}).isNumeric().contains('0');
errors = v.getErrors();
assert.equal(errors.length, 2);
assert.equal(errors[0], 'testData.number should be a real number');
assert.equal(errors[1], 'testData.number ff should contain a 0');
},
'test: custom messages with custom messageBuilder': function () {
var v = new Validator({
messageBuilder: function(msg, args) {
return msg + " " + args.join(' ');
}});
v.check(testData.number, {
isNumeric: 'testData.number should be a real number',
contains: 'testData.number should contain a'
}).isNumeric().contains('0');
errors = v.getErrors();
assert.equal(errors.length, 2);
assert.equal(errors[0], 'testData.number should be a real number ff');
assert.equal(errors[1], 'testData.number should contain a ff 0');
}
}

View File

@@ -0,0 +1,12 @@
[
{ name: 'validator', file: './validator.test.js' },
{ name: 'filter', file: './filter.test.js' },
{ name: 'messages', file: './messages.test.js' },
{ name: 'index exports', file: './index.test.js' }
].forEach(function(suite) {
var tests = require(suite.file),
test;
for (test in tests) {
console.log('Initializing ' + suite.name + ' test:', test);
}
});

View File

@@ -0,0 +1,742 @@
var node_validator = require('../lib'),
util = require('util')
Validator = new node_validator.Validator(),
ValidatorError = node_validator.ValidatorError,
assert = require('assert');
function dateFixture() {
return {
tomorrow: new Date(Date.now() + 86400000)
, yesterday: new Date(Date.now() - 86400000)
};
}
var FakeError = function(msg) {
Error.captureStackTrace(this, this);
this.name = 'FakeError';
this.message = msg;
};
util.inherits(FakeError, Error);
module.exports = {
'test #isEmail()': function () {
//Try some invalid emails
var invalid = [
'invalidemail@',
'invalid.com',
'@invalid.com'
];
invalid.forEach(function(email) {
try {
Validator.check(email, 'Invalid').isEmail();
assert.ok(false, 'Invalid email ('+email+') passed validation');
} catch(e) {
assert.equal('Invalid', e.message);
}
});
//Now try some valid ones
var valid = [
'foo@bar.com',
'x@x.x',
'foo@bar.com.au',
'foo+bar@bar.com'
];
try {
valid.forEach(function(email) {
Validator.check(email).isEmail();
});
} catch(e) {
assert.ok(false, 'A valid email did not pass validation');
}
},
'test #isUrl()': function () {
//Try some invalid URLs
var invalid = [
'xyz://foobar.com', //Only http, https and ftp are valid
'invalid/',
'invalid.x',
'invalid.',
'.com',
'http://com/',
'http://300.0.0.1/',
'mailto:foo@bar.com'
];
invalid.forEach(function(url) {
try {
Validator.check(url, 'Invalid').isUrl();
assert.ok(false, 'Invalid url ('+url+') passed validation');
} catch(e) {
assert.equal('Invalid', e.message);
}
});
//Now try some valid ones
var valid = [
'foobar.com',
'www.foobar.com',
'foobar.com/',
'valid.au',
'http://www.foobar.com/',
'https://www.foobar.com/',
'ftp://www.foobar.com/',
'http://www.foobar.com/~foobar',
'http://user:pass@www.foobar.com/',
'http://127.0.0.1/',
'http://10.0.0.0/',
'http://189.123.14.13/',
'http://duckduckgo.com/?q=%2F',
'http://foobar.com/t$-_.+!*\'(),',
'http://localhost:3000/'
];
try {
valid.forEach(function(url) {
Validator.check(url).isUrl();
});
} catch(e) {
assert.ok(false, 'A valid url did not pass validation');
}
},
'test #isIP()': function () {
//Try some invalid IPs
var invalid = [
'abc',
'256.0.0.0',
'0.0.0.256'
];
invalid.forEach(function(ip) {
try {
Validator.check(ip, 'Invalid').isIP();
assert.ok(false, 'Invalid IP ('+ip+') passed validation');
} catch(e) {
assert.equal('Invalid', e.message);
}
});
//Now try some valid ones
var valid = [
'127.0.0.1',
'0.0.0.0',
'255.255.255.255',
'1.2.3.4'
];
try {
valid.forEach(function(ip) {
Validator.check(ip).isIP();
});
} catch(e) {
assert.ok(false, 'A valid IP did not pass validation');
}
},
'test #isAlpha()': function () {
assert.ok(Validator.check('abc').isAlpha());
assert.ok(Validator.check('ABC').isAlpha());
assert.ok(Validator.check('FoObAr').isAlpha());
['123',123,'abc123',' ',''].forEach(function(str) {
try {
Validator.check(str).isAlpha();
assert.ok(false, 'isAlpha failed');
} catch (e) {}
});
},
'test #isAlphanumeric()': function () {
assert.ok(Validator.check('abc13').isAlphanumeric());
assert.ok(Validator.check('123').isAlphanumeric());
assert.ok(Validator.check('F1oO3bAr').isAlphanumeric());
['(*&ASD',' ','.',''].forEach(function(str) {
try {
Validator.check(str).isAlphanumeric();
assert.ok(false, 'isAlphanumeric failed');
} catch (e) {}
});
},
'test #isNumeric()': function () {
assert.ok(Validator.check('123').isNumeric());
assert.ok(Validator.check('00123').isNumeric());
assert.ok(Validator.check('-00123').isNumeric());
assert.ok(Validator.check('0').isNumeric());
assert.ok(Validator.check('-0').isNumeric());
['123.123',' ','.',''].forEach(function(str) {
try {
Validator.check(str).isNumeric();
assert.ok(false, 'isNumeric failed');
} catch (e) {}
});
},
'test #isLowercase()': function () {
assert.ok(Validator.check('abc').isLowercase());
assert.ok(Validator.check('foobar').isLowercase());
assert.ok(Validator.check('a').isLowercase());
assert.ok(Validator.check('123').isLowercase());
assert.ok(Validator.check('abc123').isLowercase());
assert.ok(Validator.check('this is lowercase.').isLowercase());
assert.ok(Validator.check('très über').isLowercase());
['123A','ABC','.',''].forEach(function(str) {
try {
Validator.check(str).isLowercase();
assert.ok(false, 'isLowercase failed');
} catch (e) {}
});
},
'test #isUppercase()': function () {
assert.ok(Validator.check('FOOBAR').isUppercase());
assert.ok(Validator.check('A').isUppercase());
assert.ok(Validator.check('123').isUppercase());
assert.ok(Validator.check('ABC123').isUppercase());
['abc','123aBC','.',''].forEach(function(str) {
try {
Validator.check(str).isUppercase();
assert.ok(false, 'isUpper failed');
} catch (e) {}
});
},
'test #isInt()': function () {
assert.ok(Validator.check('13').isInt());
assert.ok(Validator.check('123').isInt());
assert.ok(Validator.check('0').isInt());
assert.ok(Validator.check(0).isInt());
assert.ok(Validator.check(123).isInt());
assert.ok(Validator.check('-0').isInt());
['01', '-01', '000', '100e10', '123.123', ' ', ''].forEach(function(str) {
try {
Validator.check(str).isInt();
assert.ok(false, 'falsepositive');
} catch (e) {
if (e.message == 'falsepositive') {
e.message = 'isInt had a false positive: ' + str;
throw e;
}
}
});
},
'test #isDecimal()': function () {
assert.ok(Validator.check('123').isDecimal());
assert.ok(Validator.check('123.').isDecimal());
assert.ok(Validator.check('123.123').isDecimal());
assert.ok(Validator.check('-123.123').isDecimal());
assert.ok(Validator.check('0.123').isDecimal());
assert.ok(Validator.check('.123').isDecimal());
assert.ok(Validator.check('.0').isDecimal());
assert.ok(Validator.check('0').isDecimal());
assert.ok(Validator.check('-0').isDecimal());
assert.ok(Validator.check('01.123').isDecimal());
assert.ok(Validator.check('2.2250738585072011e-308').isDecimal());
assert.ok(Validator.check('-0.22250738585072011e-307').isDecimal());
assert.ok(Validator.check('-0.22250738585072011E-307').isDecimal());
['-.123',' ',''].forEach(function(str) {
try {
Validator.check(str).isDecimal();
assert.ok(false, 'falsepositive');
} catch (e) {
if (e.message == 'falsepositive') {
e.message = 'isDecimal had a false positive: ' + str;
throw e;
}
}
});
},
//Alias for isDecimal()
'test #isFloat()': function () {
assert.ok(Validator.check('0.5').isFloat());
},
'test #isNull()': function () {
assert.ok(Validator.check('').isNull());
assert.ok(Validator.check().isNull());
[' ','123','abc'].forEach(function(str) {
try {
Validator.check(str).isNull();
assert.ok(false, 'isNull failed');
} catch (e) {}
});
},
'test #notNull()': function () {
assert.ok(Validator.check('abc').notNull());
assert.ok(Validator.check('123').notNull());
assert.ok(Validator.check(' ').notNull());
[false,''].forEach(function(str) {
try {
Validator.check(str).notNull();
assert.ok(false, 'notNull failed');
} catch (e) {}
});
},
'test #notEmpty()': function () {
assert.ok(Validator.check('abc').notEmpty());
assert.ok(Validator.check('123').notEmpty());
assert.ok(Validator.check(' 123 ').notEmpty());
assert.ok(Validator.check([1,2]).notEmpty());
[false,' ','\r\n',' ','', NaN, []].forEach(function(str) {
try {
Validator.check(str).notEmpty();
assert.ok(false, 'notEmpty failed');
} catch (e) {}
});
},
'test #equals()': function () {
assert.ok(Validator.check('abc').equals('abc'));
assert.ok(Validator.check('123').equals(123));
assert.ok(Validator.check(' ').equals(' '));
assert.ok(Validator.check().equals(''));
try {
Validator.check(123).equals('abc');
assert.ok(false, 'equals failed');
} catch (e) {}
try {
Validator.check('').equals(' ');
assert.ok(false, 'equals failed');
} catch (e) {}
},
'test #contains()': function () {
assert.ok(Validator.check('abc').contains('abc'));
assert.ok(Validator.check('foobar').contains('oo'));
assert.ok(Validator.check('abc').contains('a'));
assert.ok(Validator.check(' ').contains(' '));
try {
Validator.check('abc').contains('');
assert.ok(false, 'contains failed');
} catch (e) {}
try {
Validator.check(123).contains('abc');
assert.ok(false, 'contains failed');
} catch (e) {}
try {
Validator.check('\t').contains('\t\t');
assert.ok(false, 'contains failed');
} catch (e) {}
},
'test #notContains()': function () {
assert.ok(Validator.check('abc').notContains('a '));
assert.ok(Validator.check('foobar').notContains('foobars'));
assert.ok(Validator.check('abc').notContains('123'));
try {
Validator.check(123).notContains(1);
assert.ok(false, 'notContains failed');
} catch (e) {}
try {
Validator.check(' ').contains('');
assert.ok(false, 'notContains failed');
} catch (e) {}
},
'test #regex()': function () {
assert.ok(Validator.check('abc').regex(/a/));
assert.ok(Validator.check('abc').regex(/^abc$/));
assert.ok(Validator.check('abc').regex('abc'));
assert.ok(Validator.check('ABC').regex(/^abc$/i));
assert.ok(Validator.check('ABC').regex('abc', 'i'));
assert.ok(Validator.check(12390947686129).regex(/^[0-9]+$/));
//Check the is() alias
assert.ok(Validator.check(12390947686129).is(/^[0-9]+$/));
try {
Validator.check(123).regex(/^1234$/);
assert.ok(false, 'regex failed');
} catch (e) {}
},
'test #notRegex()': function () {
assert.ok(Validator.check('foobar').notRegex(/e/));
assert.ok(Validator.check('ABC').notRegex('abc'));
assert.ok(Validator.check(12390947686129).notRegex(/a/));
//Check the not() alias
assert.ok(Validator.check(12390947686129).not(/^[a-z]+$/));
try {
Validator.check(123).notRegex(/123/);
assert.ok(false, 'regex failed');
} catch (e) {}
},
'test #len()': function () {
assert.ok(Validator.check('a').len(1));
assert.ok(Validator.check(123).len(2));
assert.ok(Validator.check(123).len(2, 4));
assert.ok(Validator.check(12).len(2,2));
try {
Validator.check('abc').len(4);
assert.ok(false, 'len failed');
} catch (e) {}
try {
Validator.check('abcd').len(1, 3);
assert.ok(false, 'len failed');
} catch (e) {}
},
'test #isUUID()': function () {
////xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx
assert.ok(Validator.check('A987FBC9-4BED-3078-CF07-9141BA07C9F3').isUUID());
assert.ok(Validator.check('A987FBC9-4BED-3078-CF07-9141BA07C9F3').isUUID(1));
assert.ok(Validator.check('A987FBC9-4BED-3078-CF07-9141BA07C9F3').isUUID(2));
assert.ok(Validator.check('A987FBC9-4BED-3078-CF07-9141BA07C9F3').isUUID(3));
assert.ok(Validator.check('A987FBC9-4BED-4078-8F07-9141BA07C9F3').isUUID(4));
assert.ok(Validator.check('A987FBC9-4BED-5078-AF07-9141BA07C9F3').isUUID(5));
var badUuids = [
"",
null,
"xxxA987FBC9-4BED-3078-CF07-9141BA07C9F3",
"A987FBC9-4BED-3078-CF07-9141BA07C9F3xxx",
"A987FBC94BED3078CF079141BA07C9F3",
"934859",
"987FBC9-4BED-3078-CF07A-9141BA07C9F3",
"AAAAAAAA-1111-1111-AAAG-111111111111"
]
badUuids.forEach(function (item) {
assert.throws(function() { Validator.check(item).isUUID() }, /not a uuid/i);
assert.throws(function() { Validator.check(item).isUUID(1) }, /not a uuid/i);
assert.throws(function() { Validator.check(item).isUUID(2) }, /not a uuid/i);
assert.throws(function() { Validator.check(item).isUUID(3) }, /not a uuid/i);
assert.throws(function() { Validator.check(item).isUUID(4) }, /not a uuid/i);
assert.throws(function() { Validator.check(item).isUUID(5) }, /not a uuid/i);
});
try {
Validator.check('A987FBC9-4BED-5078-0F07-9141BA07C9F3').isUUID(5);
assert.ok(false, 'isUUID failed');
} catch (e) {}
try {
Validator.check('A987FBC9-4BED-4078-0F07-9141BA07C9F3').isUUID(4);
assert.ok(false, 'isUUID failed');
} catch (e) {}
try {
Validator.check('abc').isUUID();
assert.ok(false, 'isUUID failed');
} catch (e) {}
try {
Validator.check('A987FBC932-4BED-3078-CF07-9141BA07C9').isUUID();
assert.ok(false, 'isUUID failed');
} catch (e) {}
try {
Validator.check('A987FBG9-4BED-3078-CF07-9141BA07C9DE').isUUID();
assert.ok(false, 'isUUID failed');
} catch (e) {}
},
'test #isUUIDv3()': function () {
////xxxxxxxx-xxxx-3xxx-yxxx-xxxxxxxxxxxx where x is any hexadecimal digit and y is one of 8, 9, A, or B
var goodUuidV3s = [
"987FBC97-4BED-3078-AF07-9141BA07C9F3"
]
goodUuidV3s.forEach(function (item) {
assert.ok(Validator.check(item).isUUIDv3());
});
var badUuidV3s = [
"",
null,
"xxxA987FBC9-4BED-3078-CF07-9141BA07C9F3",
"A987FBC9-4BED-3078-CF07-9141BA07C9F3xxx",
"A987FBC94BED3078CF079141BA07C9F3",
"934859",
"987FBC9-4BED-3078-CF07A-9141BA07C9F3",
"AAAAAAAA-1111-1111-AAAG-111111111111"
]
badUuidV3s.forEach(function (item) {
assert.throws(function() { Validator.check(item).isUUIDv3() }, /not a uuid v3/i);
});
},
'test #isUUIDv4()': function () {
////xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx where x is any hexadecimal digit and y is one of 8, 9, A, or B
var goodUuidV4s = [
"713ae7e3-cb32-45f9-adcb-7c4fa86b90c1",
"625e63f3-58f5-40b7-83a1-a72ad31acffb",
"57b73598-8764-4ad0-a76a-679bb6640eb1",
"9c858901-8a57-4791-81fe-4c455b099bc9"
]
goodUuidV4s.forEach(function (item) {
assert.ok(Validator.check(item).isUUIDv4());
});
var badUuidV4s = [
"",
null,
"xxxA987FBC9-4BED-3078-CF07-9141BA07C9F3",
"A987FBC9-4BED-3078-CF07-9141BA07C9F3xxx",
"A987FBC94BED3078CF079141BA07C9F3",
"934859",
"987FBC9-4BED-3078-CF07A-9141BA07C9F3",
"AAAAAAAA-1111-1111-AAAG-111111111111",
"9a47c6fa-e388-1f4f-8c67-77ef5f476ff6"
]
badUuidV4s.forEach(function (item) {
assert.throws(function() { Validator.check(item).isUUIDv4() }, /not a uuid v4/i);
});
},
'test #isUUIDv5()': function () {
////xxxxxxxx-xxxx-5xxx-yxxx-xxxxxxxxxxxx where x is any hexadecimal digit and y is one of 8, 9, A, or B
var goodUuidV5s = [
"987FBC97-4BED-5078-AF07-9141BA07C9F3",
"987FBC97-4BED-5078-BF07-9141BA07C9F3",
"987FBC97-4BED-5078-8F07-9141BA07C9F3",
"987FBC97-4BED-5078-9F07-9141BA07C9F3"
];
goodUuidV5s.forEach(function (item) {
assert.ok(Validator.check(item).isUUIDv5());
});
var badUuidV5s = [
"",
null,
"xxxA987FBC9-4BED-5078-CF07-9141BA07C9F3",
"A987FBC9-4BED-5078-CF07-9141BA07C9F3xxx",
"A987FBC94BED5078CF079141BA07C9F3",
"934859",
"987FBC9-4BED-5078-CF07A-9141BA07C9F3",
"AAAAAAAA-1111-1111-AAAG-111111111111"
];
badUuidV5s.forEach(function (item) {
assert.throws(function() { Validator.check(item).isUUIDv5(); }, /not a uuid v5/i);
});
},
'test #isIn(options)': function () {
assert.ok(Validator.check('foo').isIn('foobar'));
assert.ok(Validator.check('foo').isIn('I love football'));
assert.ok(Validator.check('foo').isIn(['foo', 'bar', 'baz']));
assert.ok(Validator.check('1').isIn([1, 2, 3]));
assert.throws(function() {
Validator.check('foo').isIn(['bar', 'baz']);
}, /unexpected/i
);
assert.throws(function() {
Validator.check('foo').isIn('bar, baz');
}, /unexpected/i
);
assert.throws(function() {
Validator.check('foo').isIn(1234567);
}, /invalid/i
);
assert.throws(function() {
Validator.check('foo').isIn({foo:"foo",bar:"bar"});
}, /invalid/i
);
},
'test #notIn(options)': function () {
assert.ok(Validator.check('foo').notIn('bar'));
assert.ok(Validator.check('foo').notIn('awesome'));
assert.ok(Validator.check('foo').notIn(['foobar', 'bar', 'baz']));
assert.throws(function() {
Validator.check('foo').notIn(['foo', 'bar', 'baz']);
}, /unexpected/i
);
assert.throws(function() {
Validator.check('foo').notIn('foobar');
}, /unexpected/i
);
assert.throws(function() {
Validator.check('1').notIn([1, 2, 3]);
}, /unexpected/i);
assert.throws(function() {
Validator.check('foo').notIn(1234567);
}, /invalid/i
);
assert.throws(function() {
Validator.check('foo').notIn({foo:"foo",bar:"bar"});
}, /invalid/i
);
},
'test #isDate()': function() {
assert.ok(Validator.check('2011-08-04').isDate());
assert.ok(Validator.check('04. 08. 2011.').isDate());
assert.ok(Validator.check('08/04/2011').isDate());
assert.ok(Validator.check('2011.08.04').isDate());
assert.ok(Validator.check('4. 8. 2011. GMT').isDate());
assert.ok(Validator.check('2011-08-04 12:00').isDate());
assert.throws(Validator.check('foo').isDate);
assert.throws(Validator.check('2011-foo-04').isDate);
assert.throws(Validator.check('GMT').isDate);
},
'test #min()': function() {
assert.ok(Validator.check('4').min(2));
assert.ok(Validator.check('5').min(5));
assert.ok(Validator.check('3.2').min(3));
assert.ok(Validator.check('4.2').min(4.2));
assert.throws(function() {
Validator.check('5').min(10);
});
assert.throws(function() {
Validator.check('5.1').min(5.11);
});
},
'test #max()': function() {
assert.ok(Validator.check('4').max(5));
assert.ok(Validator.check('7').max(7));
assert.ok(Validator.check('6.3').max(7));
assert.ok(Validator.check('2.9').max(2.9));
assert.throws(function() {
Validator.check('5').max(2);
});
assert.throws(function() {
Validator.check('4.9').max(4.2);
});
},
'test #isDate()': function() {
assert.ok(Validator.check('2011-08-04').isDate());
assert.ok(Validator.check('04. 08. 2011.').isDate());
assert.ok(Validator.check('08/04/2011').isDate());
assert.ok(Validator.check('2011.08.04').isDate());
assert.ok(Validator.check('4. 8. 2011. GMT').isDate());
assert.ok(Validator.check('2011-08-04 12:00').isDate());
assert.throws(Validator.check('foo').isDate);
assert.throws(Validator.check('2011-foo-04').isDate);
assert.throws(Validator.check('GMT').isDate);
},
'test #isAfter()': function() {
var f = dateFixture();
assert.ok(Validator.check('2011-08-04').isAfter('2011-08-03'));
assert.ok(Validator.check(f.tomorrow).isAfter());
assert.throws(function() {
Validator.check('08/04/2011').isAfter('2011-09-01');
});
assert.throws(function() {
Validator.check(f.yesterday).isAfter();
});
assert.throws(function() {
Validator.check('2011-09-01').isAfter('2011-09-01');
});
},
'test #isBefore()': function() {
var f = dateFixture();
assert.ok(Validator.check('2011-08-04').isBefore('2011-08-06'));
assert.ok(Validator.check(f.yesterday).isBefore());
assert.throws(function() {
Validator.check('08/04/2011').isBefore('2011-07-01');
});
assert.throws(function() {
Validator.check(f.tomorrow).isBefore();
});
assert.throws(function() {
Validator.check('2011-09-01').isBefore('2011-09-01');
});
},
'test #isDivisibleBy()': function() {
assert.ok(Validator.check('10').isDivisibleBy(2));
assert.ok(Validator.check('6').isDivisibleBy(3));
assert.throws(function() {
Validator.check('10').isDivisibleBy('alpha');
});
assert.throws(function() {
Validator.check('alpha').isDivisibleBy(2);
});
assert.throws(function() {
Validator.check('alpha').isDivisibleBy('alpha');
});
assert.throws(function() {
Validator.check('5').isDivisibleBy(2);
});
assert.throws(function() {
Validator.check('6.7').isDivisibleBy(3);
});
},
'test error is instanceof ValidatorError': function() {
try {
Validator.check('not_an_email', 'Invalid').isEmail();
} catch(e) {
assert.strictEqual(true, e instanceof ValidatorError);
assert.strictEqual(true, e instanceof Error);
assert.notStrictEqual(true, e instanceof FakeError);
}
},
'test false as error message': function() {
var v = new node_validator.Validator()
, error = null;
v.error = function (msg) {
error = msg;
};
v.check('not_an_email', false).isEmail();
assert.strictEqual(error, false);
}
}

File diff suppressed because one or more lines are too long

File diff suppressed because it is too large Load Diff

67
node_modules/resanitize/package.json generated vendored Normal file
View File

@@ -0,0 +1,67 @@
{
"name": "resanitize",
"author": {
"name": "Dan MacTough",
"email": "danmactough@gmail.com"
},
"description": "Regular expression-based HTML sanitizer and ad remover, geared toward RSS feed descriptions",
"version": "0.3.0",
"keywords": [
"sanitize",
"html",
"regexp",
"security"
],
"homepage": "http://github.com/danmactough/node-resanitize",
"repository": {
"type": "git",
"url": "git://github.com/danmactough/node-resanitize.git"
},
"bugs": {
"url": "http://github.com/danmactough/node-resanitize/issues"
},
"main": "./resanitize.js",
"engines": {
"node": ">= 0.6.0"
},
"dependencies": {
"validator": "~1.5.1"
},
"devDependencies": {
"mocha": "~1.13.0"
},
"licenses": [
{
"type": "MIT",
"url": "https://raw.github.com/danmactough/node-resanitize/master/LICENSE"
}
],
"directories": {
"test": "test"
},
"scripts": {
"test": "mocha"
},
"license": "MIT",
"readme": "# Resanitize - Regular expression-based HTML sanitizer and ad remover, geared toward RSS feed descriptions\n\nThis node.js module provides functions for removing unsafe parts and ads from\nHTML. I am using it for the &lt;description&gt; element of RSS feeds.\n\n## Installation\n\nnpm install resanitize\n\n## Usage\n\n```javascript\n\n var resanitize = require('resanitize')\n , html = '<div style=\"border: 400px solid pink;\">Headline</div>'\n ;\n\n resanitize(html); // => '<div>Headline</div>'\n```\n\n## Notes\n\nThis module's opinion of \"sanitized\" might not meet your security requirements.\nThe mere fact that it uses regular expressions should make this disclaimer\nunnecessary, but just to be clear: if you intend to display arbitrary user input\nthat includes HTML, you're going to want something more robust.\n\nAs of v0.3.0, we've added [node-validator's](//github.com/chriso/node-validator) XSS\nfilter. It's certainly an improvement, but still -- be careful. Any concerns\nabout XSS attacks should be directered to [node-validator's issue tracker](//github.com/chriso/node-validator/issues).\n\nNote that the `stripUnsafeTags` method will loop over the strip an arbitrary\nnumber of times (2) to try to strip maliciously nested html tags. After the\nmaximum number of iterations is reached, if the string still appears to contain\nany unsafe tags, it is deemed unsafe and set to an empty string. If this seems\nunexpected and/or is causing any problems, please raise an [issue](//github.com/danmactough/node-resanitize/issues).",
"readmeFilename": "README.md",
"_id": "resanitize@0.3.0",
"dist": {
"shasum": "dfcb2bf2ae1df2838439ed6cd04c78845c532353",
"tarball": "http://registry.npmjs.org/resanitize/-/resanitize-0.3.0.tgz"
},
"_from": "resanitize@*",
"_npmVersion": "1.3.11",
"_npmUser": {
"name": "danmactough",
"email": "danmactough@gmail.com"
},
"maintainers": [
{
"name": "danmactough",
"email": "danmactough@gmail.com"
}
],
"_shasum": "dfcb2bf2ae1df2838439ed6cd04c78845c532353",
"_resolved": "https://registry.npmjs.org/resanitize/-/resanitize-0.3.0.tgz"
}

290
node_modules/resanitize/resanitize.js generated vendored Normal file
View File

@@ -0,0 +1,290 @@
/*!
* resanitize - Regular expression-based HTML sanitizer and ad remover, geared toward RSS feed descriptions
* Copyright(c) 2012 Dan MacTough <danmactough@gmail.com>
* All rights reserved.
*/
/**
* Dependencies
*/
var validator = require('validator');
/**
* Remove unsafe parts and ads from HTML
*
* Example:
*
* var resanitize = require('resanitize');
* resanitize('<div style="border: 400px solid pink;">Headline</div>');
* // => '<div>Headline</div>'
*
* References:
* - http://en.wikipedia.org/wiki/C0_and_C1_control_codes
* - http://en.wikipedia.org/wiki/Unicode_control_characters
* - http://www.utf8-chartable.de/unicode-utf8-table.pl
*
* @param {String|Buffer} HTML string to sanitize
* @return {String} sanitized HTML
* @api public
*/
function resanitize (str) {
if ('string' !== typeof str) {
if (Buffer.isBuffer(str)) {
str = str.toString();
}
else {
throw new TypeError('Invalid argument: must be String or Buffer');
}
}
str = stripAsciiCtrlChars(str);
str = stripExtendedCtrlChars(str);
str = fixSpace(str);
str = stripComments(str);
str = stripAds(str); // It's important that this comes before the remainder
// because it matches on certain attribute values that
// get stripped below.
str = validator.sanitize(str).xss().replace(/\[removed\]/g, '')
str = fixImages(str);
str = stripUnsafeTags(str);
str = stripUnsafeAttrs(str);
return str;
}
module.exports = resanitize;
/**
* Replace UTF-8 non-breaking space with a regular space and strip null bytes
*/
function fixSpace (str) {
return str.replace(/\u00A0/g, ' ') // Unicode non-breaking space
.replace(/[\u2028\u2029]/g, '') // UCS newline characters
.replace(/\0/g, '');
}
module.exports.fixSpace = fixSpace;
/**
* Strip superfluous whitespace
*/
function stripHtmlExtraSpace (str) {
return str.replace(/<(div|p)[^>]*?>\s*?(?:<br[^>]*?>)*?\s*?<\/\1>/gi, '')
.replace(/<(div|span)[^>]*?>\s*?<\/\1>/gi, '');
}
module.exports.stripHtmlExtraSpace = stripHtmlExtraSpace;
/**
* Strip ASCII control characters
*/
function stripAsciiCtrlChars (str) {
return str.replace(/[\x00-\x08\x0B\x0C\x0E-\x1F\x7F]+/g, '');
}
module.exports.stripAsciiCtrlChars = stripAsciiCtrlChars;
/**
* Strip ISO 6429 control characters
*/
function stripExtendedCtrlChars (str) {
return str.replace(/[\u0080-\u009F]+/g, '');
}
module.exports.stripExtendedCtrlChars = stripExtendedCtrlChars;
/**
* Strip HTML comments
*/
function stripComments (str) {
return str.replace(/<!--[^>]*?-->/g, '');
}
module.exports.stripComments = stripComments;
/**
* Permit only the provided attributes to remain in the tag
*/
function filterAttrs () {
var allowed = [];
if (Array.isArray(arguments[0])) {
allowed = arguments[0];
} else {
allowed = Array.prototype.slice.call(arguments);
}
return function (attr, name) {
if ( ~allowed.indexOf(name && name.toLowerCase()) ) {
return attr;
} else {
return '';
}
};
}
module.exports.filterAttrs = filterAttrs;
/**
* Strip the provided attributes from the tag
*/
function stripAttrs () {
var banned = []
, regexes = [];
if (Array.isArray(arguments[0])) {
banned = arguments[0].filter(function (attr) {
if ('string' === typeof attr) {
return true;
}
else if (attr.constructor && 'RegExp' === attr.constructor.name) {
regexes.push(attr);
}
else {
}
});
} else {
banned = Array.prototype.slice.call(arguments).filter(function (attr) {
if ('string' === typeof attr) {
return true;
}
else if (attr.constructor && 'RegExp' === attr.constructor.name) {
regexes.push(attr);
}
});
}
return function (attr, name) {
if ( ~banned.indexOf(name && name.toLowerCase()) || regexes.some(function (re) { return re.test(name); }) ) {
return '';
} else {
return attr;
}
};
}
module.exports.stripAttrs = stripAttrs;
/**
* Filter an HTML opening or self-closing tag
*/
function filterTag (nextFilter) {
return function (rematch) {
if ('function' === typeof nextFilter) {
rematch = rematch.replace(/([^\s"']+?)=("|')[^>]+?\2/g, nextFilter);
}
// Cleanup extra whitespace
return rematch.replace(/\s+/g, ' ')
.replace(/ (\/)?>/, '$1>');
};
}
module.exports.filterTag = filterTag;
function fixImages (str) {
return str.replace(/(<img[^>]*?>)/g, filterTag(filterAttrs('src', 'alt', 'title', 'height', 'width')) );
}
module.exports.fixImages = fixImages;
function stripUnsafeAttrs (str) {
var unsafe = [ 'id'
, 'class'
, 'style'
, 'accesskey'
, 'action'
, 'autocomplete'
, 'autofocus'
, 'clear'
, 'contextmenu'
, 'contenteditable'
, 'draggable'
, 'dropzone'
, 'method'
, 'tabindex'
, 'target'
, /on\w+/i
, /data-\w+/i
];
return str.replace(/<([^ >]+?) [^>]*?>/g, filterTag(stripAttrs(unsafe)));
}
module.exports.stripUnsafeAttrs = stripUnsafeAttrs;
function stripUnsafeTags (str) {
var el = /<(?:wbr|form|input|font|blink|script|style|comment|plaintext|xmp|link|listing|meta|body|frame|frameset)\b/;
var ct = 0, max = 2;
// We'll repeatedly try to strip any maliciously nested elements up to [max] times
while (el.test(str) && ct++ < max) {
str = str.replace(/<form[^>]*?>[\s\S]*?<\/form>/gi, '')
.replace(/<input[^>]*?>[\s\S]*?<\/input>/gi, '')
.replace(/<\/?(?:form|input|font|blink)[^>]*?>/gi, '')
// These are XSS/security risks
.replace(/<script[^>]*?>[\s\S]*?<\/script>/gi, '')
.replace(/<(\/)*wbr[^>]*?>/gi, '')
.replace(/<style[^>]*?>[\s\S]*?<\/style>/gi, '') // shouldn't work anyway...
.replace(/<comment[^>]*?>[\s\S]*?<\/comment>/gi, '')
.replace(/<plaintext[^>]*?>[\s\S]*?<\/plaintext>/gi, '')
.replace(/<xmp[^>]*?>[\s\S]*?<\/xmp>/gi, '')
.replace(/<\/?(?:link|listing|meta|body|frame|frameset)[^>]*?>/gi, '')
// Delete iframes, except those inserted by Google in lieu of video embeds
.replace(/<iframe(?![^>]*?src=("|')\S+?reader.googleusercontent.com\/reader\/embediframe.+?\1)[^>]*?>[\s\S]*?<\/iframe>/gi, '')
;
}
if (el.test(str)) {
// We couldn't safely strip the HTML, so we return an empty string
return '';
}
return str;
}
module.exports.stripUnsafeTags = stripUnsafeTags;
function stripAds (str) {
return str.replace(/<div[^>]*?class=("|')snap_preview\1[^>]*?>(?:<br[^>]*?>)?([\s\S]*?)<\/div>/gi, '$2')
.replace(/<div[^>]*?class=("|')(?:feedflare|zemanta-pixie)\1[^>]*?>[\s\S]*?<\/div>/gi, '')
.replace(/<!--AD BEGIN-->[\s\S]*?<!--AD END-->\s*/gi, '')
.replace(/<table[^>]*?>[\s\S]*?<\/table>\s*?<div[^>]*?>[\s\S]*?Ads by Pheedo[\s\S]*?<\/div>/gi, '')
.replace(/<table[^>]*?>.*?<img[^>]*?src=("|')[^>]*?advertisement[^>]*?\1.*?>.*?<\/table>/gi, '')
.replace(/<br[^>]*?>\s*?<br[^>]*?>\s*?<span[^>]*?class=("|')advertisement\1[^>]*?>[\s\S]*?<\/span>[\s\S]*<div[^>]*?>[\s\S]*?Ads by Pheedo[\s\S]*?<\/div>/gi, '')
.replace(/<br[^>]*?>\s*?<br[^>]*?>\s*?(?:<[^>]+>\s*)*?<hr[^>]*?>\s*?<div[^>]*?>(?:Featured Advertiser|Presented By:)<\/div>[\s\S]*<div[^>]*?>[\s\S]*?(?:Ads by Pheedo|ads\.pheedo\.com)[\s\S]*?<\/div>/gi, '')
.replace(/<br[^>]*?>\s*?<br[^>]*?>\s*?<a[^>]*?href=("|')http:\/\/[^>]*?\.?(?:pheedo|pheedcontent)\.com\/[^>]*?\1[\s\S]*?<\/a>[\s\S]*$/gim, '')
.replace(/<div[^>]*?class=("|')cbw snap_nopreview\1[^>]*?>[\s\S]*$/gim, '')
.replace(/<div><a href=(?:"|')http:\/\/d\.techcrunch\.com\/ck\.php[\s\S]*?<\/div> */gi, '')
.replace(/<(p|div)[^>]*?>\s*?<a[^>]*?href=("|')[^>]+?\2[^>]*?><img[^>]*?src=("|')http:\/\/(?:feedads\.googleadservices|feedproxy\.google|feeds2?\.feedburner)\.com\/(?:~|%7e)[^>]*?\/[^>]+?\3[^>]*?>[\s\S]*?<\/\1>/gi, '')
.replace(/<(p|div)[^>]*?>\s*?<a[^>]*?href=("|')[^>]+?\2[^>]*?><img[^>]*?src=("|')http:\/\/feeds\.[^>]+?\.[^>]+?\/(?:~|%7e)[^>]\/[^>]+?\3[^>]*?>[\s\S]*?<\/\1>/gi, '')
.replace(/<a[^>]*?href=("|')http:\/\/feeds\.[^>]+?\.[^>]+?\/(?:~|%7e)[a-qs-z]\/[^>]+?\1[\s\S]*?<\/a>/gi, '')
.replace(/<a[^>]*?href=("|')http:\/\/[^>]*?\.?addtoany\.com\/[^>]*?\1[\s\S]*?<\/a>/gi, '')
.replace(/<a[^>]*?href=("|')http:\/\/feeds\.wordpress\.com\/[\.\d]+?\/(?:comments|go[\s\S]*)\/[^>]+?\1[\s\S]*?<\/a> ?/gi, '')
.replace(/<a[^>]*?href=("|')http:\/\/[^>]*?\.?doubleclick\.net\/[^>]*?\1[\s\S]*?<\/a>/gi, '')
.replace(/<a[^>]*?href=("|')http:\/\/[^>]*?\.?fmpub\.net\/adserver\/[^>]*?\1[\s\S]*?<\/a>/gi, '')
.replace(/<a[^>]*?href=("|')http:\/\/[^>]*?\.?eyewonderlabs\.com\/[^>]*?\1[\s\S]*?<\/a>/gi, '')
.replace(/<a[^>]*?href=("|')http:\/\/[^>]*?\.?pheedo\.com\/[^>]*?\1[\s\S]*?<\/a>/gi, '')
.replace(/<a[^>]*?href=("|')http:\/\/api\.tweetmeme\.com\/share\?[^>]*?\1[\s\S]*?<\/a>/gi, '')
.replace(/<p><a[^>]*?href=("|')http:\/\/rss\.cnn\.com\/+?(?:~|%7e)a\/[^>]*?\1[\s\S]*?<\/p>/gi, '')
.replace(/<img[^>]*?src=("|')http:\/\/feeds\.[^>]+?\.[^>]+?\/(?:~|%7e)r\/[^>]+?\1[\s\S]*?>/gi, '')
.replace(/<img[^>]*?src=("|')http:\/\/rss\.nytimes\.com\/c\/[^>]*?\1.*?>.*$/gim, '')
.replace(/<img[^>]*?src=("|')http:\/\/feeds\.washingtonpost\.com\/c\/[^>]*?\1.*?>.*$/gim, '')
.replace(/<img[^>]*?src=("|')http:\/\/[^>]*?\.?feedsportal\.com\/c\/[^>]*?\1.*?>.*$/gim, '')
.replace(/<img[^>]*?src=("|')http:\/\/(?:feedads\.googleadservices|feedproxy\.google|feeds2\.feedburner)\.com\/(?:~|%7e)r\/[^>]+?\1[\s\S]*?>/gi, '')
.replace(/<img[^>]*?src=("|')http:\/\/rss\.cnn\.com\/~r\/[^>]*?\1[\s\S]*?>/gi, '')
.replace(/<img[^>]*?src=("|')http:\/\/[^>]*?\.?fmpub\.net\/adserver\/[^>]*?\1[\s\S]*?>/gi, '')
.replace(/<img[^>]*?src=("|')http:\/\/[^>]*?\.?pheedo\.com\/[^>]*?\1[\s\S]*?>/gi, '')
.replace(/<img[^>]*?src=("|')http:\/\/stats\.wordpress\.com\/[\w]\.gif\?[^>]*?\1[\s\S]*?>/gi, '')
.replace(/<img[^>]*?src=("|')http:\/\/feeds\.wired\.com\/c\/[^>]*?\1.*?>.*$/gim, '')
.replace(/<p><strong><em>Crunch Network[\s\S]*?<\/p>/gi, '')
.replace(/<embed[^>]*?castfire_player[\s\S]*?> *?(<\/embed>)?/gi, '')
.replace(/<embed[^>]*?src=("|')[^>]*?castfire\.com[^>]+?\1[\s\S]*?> *?(<\/embed>)?/gi, '')
.replace(/<p align=("|')right\1><em>Sponsor<\/em>[\s\S]*?<\/p>/gi, '')
.replace(/<div [\s\S]*?<img [^>]*?src=(?:"|')[^>]*?\/share-buttons\/[\s\S]*?<\/div>[\s]*/gi, '')
// This is that annoying footer in every delicious item
.replace(/<span[^>]*?>\s*?<a[^>]*?href=("|')[^\1]+?src=feed_newsgator\1[^>]*?>[\s\S]*<\/span>/gi, '')
// This is the annoying footer from ATL
.replace(/<p[^>]*?><strong><a[^>]*?href=("|')[^>]*?abovethelaw\.com\/[\s\S]+?\1[^>]*?>Continue reading[\s\S]*<\/p>/gi, '')
// This is the annoying link at the end of WaPo articles
.replace(/<a[^>]*?>Read full article[\s\S]*?<\/a>/gi, '')
// These ads go...
.replace(/<div[^>]*?><a[^>]*?href=("|')[^>]*?crunchbase\.com\/company\/[\s\S]+?\1[^>]*?>[\s\S]*?<div[\s\S]*?>Loading information about[\s\S]*?<\/div>/gi, '')
.replace(/<div[^>]*?class=("|')cb_widget_[^>]+?\1[\s\S]*?><\/div>/gi, '')
.replace(/<div[^>]*?class=("|')cb_widget_[^>]+?\1[\s\S]*?>[\s\S]*?<\/div>/gi, '')
// Before these
.replace(/<a[^>]*?href=("|')[^>]*?crunchbase\.com\/\1[\s\S]*?<\/a>\s*/gi, '')
.replace(/<div[^>]*?class=("|')cb_widget\1[^>]*?>[\s\S]*?<\/div>/gi, '')
// Clean up some empty things
//.replace(/<(div|p|span)[^>]*?>(\s|<br *?\/?>|(?R))*?<\/\1>/gi, '')
.replace(/(\s|<br[^>]*?\/?>)*$/gim, '')
;
}
module.exports.stripAds = stripAds;
/**
* Dumbly strip angle brackets
*/
function stripHtml (str) {
return str.replace(/<.*?>/g, '');
}
module.exports.stripHtml = stripHtml;