jprichardson / string.js

Extra JavaScript string methods.
http://stringjs.com
1.81k stars 234 forks source link

TypeError: Cannot read property 'replace' of undefined #192

Open jorgefo opened 8 years ago

jorgefo commented 8 years ago

I have this error

TypeError: Cannot read property 'replace' of undefined at S.escapeHTML (C:\Nodejs\node_modules\string\lib\string.js:174:41)

this happend when i try this option S(req.query.ja).escapeHTML();

The value of req.query.ja is null

escapeHTML: function() { //from underscore.string return new this.constructor(this.s.replace(/[&<>"']/g, function(m){ return '&' + reversedEscapeChars[m] + ';'; })); },

I solved the problem with add this line

if (this.s == null) return '';

escapeHTML: function() { //from underscore.string if (this.s == null) return ''; return new this.constructor(this.s.replace(/[&<>"']/g, function(m){ return '&' + reversedEscapeChars[m] + ';'; })); }

This is my first post in Github sorry if this is not normal way to report this issue XD

ewrogers commented 8 years ago

Good find, fixed in PR #193 . Hopefully can be merged into master soon.