fixed sanitize handlebars helper to accept not only strings
This commit is contained in:
35
dist/swagger-ui.js
vendored
35
dist/swagger-ui.js
vendored
File diff suppressed because one or more lines are too long
18
dist/swagger-ui.min.js
vendored
18
dist/swagger-ui.min.js
vendored
File diff suppressed because one or more lines are too long
@@ -1,12 +1,26 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
/*jslint eqeq: true*/
|
/*jslint eqeq: true*/
|
||||||
|
|
||||||
var sanitize = function(html) {
|
var _sanitize = function(html) {
|
||||||
html = html || '';
|
// Strip the script tags from the html and inline evenhandlers
|
||||||
// Strip the script tags from the html, and return it as a Handlebars.SafeString
|
|
||||||
html = html.replace(/<script\b[^<]*(?:(?!<\/script>)<[^<]*)*<\/script>/gi, '');
|
html = html.replace(/<script\b[^<]*(?:(?!<\/script>)<[^<]*)*<\/script>/gi, '');
|
||||||
html = html.replace(/(on\w+="[^"]*")*(on\w+='[^']*')*(on\w+=\w*\(\w*\))*/gi, '');
|
html = html.replace(/(on\w+="[^"]*")*(on\w+='[^']*')*(on\w+=\w*\(\w*\))*/gi, '');
|
||||||
return new Handlebars.SafeString(html);
|
|
||||||
|
return html;
|
||||||
|
};
|
||||||
|
|
||||||
|
var sanitize =function (html) {
|
||||||
|
var _html;
|
||||||
|
if( _.isUndefined(html) || _.isNull(html) || _.isNumber(html)) {
|
||||||
|
return new Handlebars.SafeString(html);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (_.isObject(html)){
|
||||||
|
_html = JSON.stringify(html);
|
||||||
|
return new Handlebars.SafeString(JSON.parse(_sanitize(_html)));
|
||||||
|
}
|
||||||
|
|
||||||
|
return new Handlebars.SafeString(_sanitize(html));
|
||||||
};
|
};
|
||||||
|
|
||||||
Handlebars.registerHelper('sanitize', sanitize);
|
Handlebars.registerHelper('sanitize', sanitize);
|
||||||
|
|||||||
Reference in New Issue
Block a user