Skip to content

Commit

Permalink
Merge pull request #16 from masumsoft/master
Browse files Browse the repository at this point in the history
Issue#6: Boolean and undefined variables accidentally being converted to string
  • Loading branch information
theSmaw committed Dec 15, 2015
2 parents 69a8877 + 64dd568 commit 5f0d183
Showing 1 changed file with 30 additions and 7 deletions.
37 changes: 30 additions & 7 deletions sanitizer.js
Expand Up @@ -168,7 +168,12 @@ var html = (function(html4) {
* an HTML entity.
*/
function unescapeEntities(s) {
return s.replace(ENTITY_RE_1, decodeOneEntity);
if(s) {
return s.replace(ENTITY_RE_1, decodeOneEntity);
}
else {
return s;
}
}

var ampRe = /&/g;
Expand All @@ -190,8 +195,14 @@ var html = (function(html4) {
* }
*/
function escapeAttrib(s) {
return ('' + s).replace(ampRe, '&').replace(ltRe, '<')
if(s) {
return ('' + s).replace(ampRe, '&').replace(ltRe, '<')
.replace(gtRe, '>').replace(quotRe, '"');
}
else {
return s;
}

}

/**
Expand All @@ -202,10 +213,15 @@ var html = (function(html4) {
* }
*/
function normalizeRCData(rcdata) {
return rcdata
.replace(looseAmpRe, '&$1')
.replace(ltRe, '<')
.replace(gtRe, '>');
if(rcdata) {
return rcdata
.replace(looseAmpRe, '&$1')
.replace(ltRe, '<')
.replace(gtRe, '>');
}
else {
return rcdata;
}
}

// TODO(felix8a): validate sanitizer regexs against the HTML5 grammar at
Expand Down Expand Up @@ -1085,7 +1101,14 @@ Sanitizer.sanitize = function(inputHtml, opt_naiveUriRewriter, opt_nmTokenPolicy
if (typeof(inputHtml) === "string") {
inputHtml = inputHtml.replace(/<([a-zA-Z]+)([^>]*)\/>/g, '<$1$2></$1>');
}
return html.sanitize(inputHtml, opt_naiveUriRewriter, opt_nmTokenPolicy, opt_logger)

if (inputHtml) {
return html.sanitize(inputHtml, opt_naiveUriRewriter, opt_nmTokenPolicy, opt_logger);
}
else {
return inputHtml;
}

}

// the browser, add 'Sanitizer' as a global object via a string identifier,
Expand Down

0 comments on commit 5f0d183

Please sign in to comment.