Share Gaia assets and adapters, keep private profiles and development documents local, and update both public READMEs.
53 lines
No EOL
1.7 KiB
JavaScript
53 lines
No EOL
1.7 KiB
JavaScript
(function (root, factory) {
|
|
'use strict';
|
|
if (typeof define === 'function' && define.amd) {
|
|
define(factory);
|
|
} else if (typeof exports === 'object') {
|
|
module.exports = factory();
|
|
} else {
|
|
root.Sanitizer = factory();
|
|
}
|
|
}(this, function () {
|
|
'use strict';
|
|
var Sanitizer = {
|
|
_entity: /[&<>"'/]/g,
|
|
_entities: {
|
|
'&': '&',
|
|
'<': '<',
|
|
'>': '>',
|
|
'"': '"',
|
|
'\'': ''',
|
|
'/': '/'
|
|
},
|
|
getEntity: function (s) {
|
|
return Sanitizer._entities[s];
|
|
},
|
|
escapeHTML: function (strings, ...values) {
|
|
var result = '';
|
|
for (var i = 0; i < strings.length; i++) {
|
|
result += strings[i];
|
|
if (i < values.length) {
|
|
result += String(values[i]).replace(Sanitizer._entity, Sanitizer.getEntity);
|
|
}
|
|
}
|
|
return result;
|
|
},
|
|
createSafeHTML: function (strings, ...values) {
|
|
var escaped = Sanitizer.escapeHTML(strings, ...values);
|
|
return {
|
|
__html: escaped,
|
|
toString: function () {
|
|
return '[object WrappedHTMLObject]';
|
|
},
|
|
info: 'This is a wrapped HTML object. See https://developer.mozilla.or' + 'g/en-US/Firefox_OS/Security/Security_Automation for more.'
|
|
};
|
|
},
|
|
unwrapSafeHTML: function (...htmlObjects) {
|
|
var markupList = htmlObjects.map(function (obj) {
|
|
return obj.__html;
|
|
});
|
|
return markupList.join('');
|
|
}
|
|
};
|
|
return Sanitizer;
|
|
})); |