jprichardson/string.js

TypeError: Cannot read property 'replace' of undefined

jorgefo opened this issue · 1 comments

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

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