fix escapeHtml

This commit is contained in:
Avris 2021-11-21 17:38:20 +01:00
parent 504a2e7135
commit 48d3a85037
3 changed files with 13 additions and 9 deletions

View File

@ -1,6 +1,7 @@
<script>
import Icon from './Icon';
import spelling from "../plugins/spelling";
import { escapeHtml } from '../src/helpers';
export default {
mixins: [ spelling ],
@ -12,7 +13,7 @@
render(h) {
let text = this.text;
if (this.escape) {
text = text.replace(/[&<>"]/g, tag => escapeChars[tag] || tag);
text = escapeHtml(text);
}
if (!this.text) {
return h('span');

View File

@ -1,12 +1,6 @@
<script>
import spelling from "../plugins/spelling";
const escapeChars = {
'&': '&amp;',
'<': '&lt;',
'>': '&gt;',
'"': '&quot;'
};
import { escapeHtml } from '../src/helpers';
export default {
mixins: [ spelling ],
@ -18,7 +12,7 @@
let text = this.text || '';
text = text.replace('<script', '');
if (this.escape) {
text = text.replace(/[&<>"]/g, tag => escapeChars[tag] || tag);
text = escapeHtml(text);
}
return h('span', {domProps: { innerHTML: this.handleSpelling(text) }});

View File

@ -223,3 +223,12 @@ export const clearKey = (key) => {
export const sleep = (milliseconds) => {
return new Promise(resolve => setTimeout(resolve, milliseconds));
}
const escapeChars = {
'&': '&amp;',
'<': '&lt;',
'>': '&gt;',
'"': '&quot;'
};
export const escapeHtml = (text) => text.replace(/[&<>"]/g, tag => escapeChars[tag] || tag);