Remains of the sandboxed CKEditor - will be removed, but the version here may be useful for another editor that is prone to XSS (like Summernote).
39 lines
No EOL
655 B
JavaScript
39 lines
No EOL
655 B
JavaScript
'use strict';
|
|
|
|
module.exports = {
|
|
enforce,
|
|
cleanupFromPost,
|
|
filterObject,
|
|
castToInteger
|
|
};
|
|
|
|
function enforce(condition, message) {
|
|
if (!condition) {
|
|
throw new Error(message);
|
|
}
|
|
}
|
|
|
|
function cleanupFromPost(value) {
|
|
return (value || '').toString().trim();
|
|
}
|
|
|
|
function filterObject(obj, allowedKeys) {
|
|
const result = {};
|
|
for (const key in obj) {
|
|
if (allowedKeys.has(key)) {
|
|
result[key] = obj[key];
|
|
}
|
|
}
|
|
|
|
return result;
|
|
}
|
|
|
|
function castToInteger(id) {
|
|
const val = parseInt(id);
|
|
|
|
if (!Number.isInteger(val)) {
|
|
throw new Error('Invalid id');
|
|
}
|
|
|
|
return val;
|
|
} |