Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions src/normalize.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,18 @@
function SanitizeHtml(html) {
const SCRIPT_REGEX = /<script\b[^<]*(?:(?!<\/script>)<[^<]*)*<\/script>/gi

// Removing the <script> tags
while (SCRIPT_REGEX.test(html)) {
html = html.replace(SCRIPT_REGEX, "")
}

// Removing all events from tags...
html = html.replace(/ on\w+=["|'][^']*["|']/g, "")

return html
}


exports.processContentType = (
contentType,
createNodeId,
Expand Down Expand Up @@ -54,6 +69,17 @@ exports.processEntry = (
createContentDigest,
typePrefix
) => {
//Find uid of objects in schema that are text fields
const needSanitizing = contentType.schema.filter(obj => {
return obj.data_type === 'text';
}).map(obj => {
return obj.uid;
});
//For each text field sanitize its content.
needSanitizing.forEach((field) => {
entry[field] = SanitizeHtml(entry[field]);
});

const nodeId = makeEntryNodeUid(entry, createNodeId, typePrefix);
const nodeContent = JSON.stringify(entry);
const nodeData = {
Expand Down