Skip to content

Commit

Permalink
Move DOMPurify.sanitize to showMessageComposer
Browse files Browse the repository at this point in the history
DOMPurify.sanitize may take a while.
Save some sanitize executions by moving the sanitization to an earlier stage.

Signed-off-by: Daniel Kesselberg <[email protected]>
  • Loading branch information
kesselb committed Sep 2, 2022
1 parent e07de49 commit d877f3d
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 12 deletions.
14 changes: 2 additions & 12 deletions src/components/TextEditor.vue
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
<template>
<ckeditor
v-if="ready"
:value="sanitizedValue"
:value="value"
:config="config"
:editor="editor"
@input="onEditorInput"
Expand Down Expand Up @@ -136,11 +136,6 @@ export default {
},
}
},
computed: {
sanitizedValue() {
return this.sanitizeValue(this.value)
},
},
beforeMount() {
this.loadEditorTranslations(getLanguage())
},
Expand Down Expand Up @@ -211,6 +206,7 @@ export default {
priority: 'highest',
}
)
if (this.focus) {
logger.debug('focusing TextEditor')
editor.editing.view.focus()
Expand All @@ -220,7 +216,6 @@ export default {
this.$emit('ready', editor)
},
onEditorInput(text) {
text = this.sanitizeValue(text)
logger.debug(`TextEditor input changed to <${text}>`)
this.$emit('input', text)
},
Expand All @@ -237,11 +232,6 @@ export default {
throw new Error('Impossible to execute a command before editor is ready.')
}
},
sanitizeValue(text) {
return DOMPurify.sanitize(text, {
FORBID_TAGS: ['style'],
})
},
},
}
</script>
Expand Down
9 changes: 9 additions & 0 deletions src/store/actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ import {
buildRecipients as buildReplyRecipients,
buildReplySubject,
} from '../ReplyBuilder'
import DOMPurify from 'dompurify'

const sliceToPage = slice(0, PAGE_SIZE)

Expand Down Expand Up @@ -284,6 +285,10 @@ export default {
})
)

resp.data = DOMPurify.sanitize(resp.data, {
FORBID_TAGS: ['style'],
})

data.body = html(resp.data)
} else {
data.body = plain(original.body)
Expand Down Expand Up @@ -360,6 +365,10 @@ export default {
})
)

resp.data = DOMPurify.sanitize(resp.data, {
FORBID_TAGS: ['style'],
})

data.body = html(resp.data)
} else {
data.body = plain(message.body)
Expand Down

0 comments on commit d877f3d

Please sign in to comment.