FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Fix to handle null or undefined for escapeHTML, unescapeHTML, stripTa… · jprichardson/string.js@a68176b · GitHub

Commit a68176b

Browse files
committed
Fix to handle null or undefined for escapeHTML, unescapeHTML, stripTags, trim functions
1 parent 52ce6c1 commit a68176b

4 files changed

Lines changed: 33 additions & 1 deletion

File tree

‎dist/string.js‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -253,6 +253,9 @@ string.js - Copyright (C) 2012-2014, JP Richardson <jprichardson@gmail.com>
253253
},
254254

255255
escapeHTML: function() { //from underscore.string
256+
if (!this.s) {
257+
return new this.constructor(this.s)
258+
}
256259
return new this.constructor(this.s.replace(/[&<>"']/g, function(m){ return '&' + reversedEscapeChars[m] + ';'; }));
257260
},
258261

@@ -512,6 +515,9 @@ string.js - Copyright (C) 2012-2014, JP Richardson <jprichardson@gmail.com>
512515
},
513516

514517
stripTags: function() { //from sugar.js
518+
if (!this.s) {
519+
return new this.constructor(this.s)
520+
}
515521
var s = this.s, args = arguments.length > 0 ? arguments : [''];
516522
multiArgs(args, function(tag) {
517523
s = s.replace(RegExp('<\/?' + tag + '[^<>]*>', 'gi'), '');
@@ -576,6 +582,9 @@ string.js - Copyright (C) 2012-2014, JP Richardson <jprichardson@gmail.com>
576582
},
577583

578584
trim: function() {
585+
if (!this.s) {
586+
return new this.constructor(this.s)
587+
}
579588
var s;
580589
if (typeof __nsp.trim === 'undefined')
581590
s = this.s.replace(/(^\s*|\s*$)/g, '')
@@ -697,6 +706,9 @@ string.js - Copyright (C) 2012-2014, JP Richardson <jprichardson@gmail.com>
697706
},
698707

699708
unescapeHTML: function() { //from underscore.string
709+
if (!this.s) {
710+
return new this.constructor(this.s)
711+
}
700712
return new this.constructor(this.s.replace(/\&([^;]+);/g, function(entity, entityCode){
701713
var match;
702714

0 commit comments

Comments
 (0)

Back | FazBrowse Home | New Git URL