Skip to content

Commit be3d0ac

Browse files
committed
perf: move escape html to utils
1 parent 86bcc2b commit be3d0ac

File tree

2 files changed

+18
-13
lines changed

2 files changed

+18
-13
lines changed

src/core/render/utils.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,3 +48,20 @@ export function getAndRemoveConfig(str = '') {
4848
export function removeAtag(str = '') {
4949
return str.replace(/(<\/?a.*?>)/gi, '');
5050
}
51+
52+
/**
53+
* Escape html
54+
* @param {String} string html string
55+
* @returns {string} Return escaped html string
56+
*/
57+
export function escapeHtml(string) {
58+
const entityMap = {
59+
'&': '&amp;',
60+
'<': '&lt;',
61+
'>': '&gt;',
62+
'"': '&quot;',
63+
"'": '&#39;',
64+
};
65+
66+
return String(string).replace(/[&<>"']/g, s => entityMap[s]);
67+
}

src/plugins/search/search.js

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/* eslint-disable no-unused-vars */
2-
import { getAndRemoveConfig } from '../../core/render/utils';
2+
import { getAndRemoveConfig, escapeHtml } from '../../core/render/utils';
33

44
let INDEXS = {};
55

@@ -20,18 +20,6 @@ function resolveIndexKey(namespace) {
2020
: LOCAL_STORAGE.INDEX_KEY;
2121
}
2222

23-
function escapeHtml(string) {
24-
const entityMap = {
25-
'&': '&amp;',
26-
'<': '&lt;',
27-
'>': '&gt;',
28-
'"': '&quot;',
29-
"'": '&#39;',
30-
};
31-
32-
return String(string).replace(/[&<>"']/g, s => entityMap[s]);
33-
}
34-
3523
function getAllPaths(router) {
3624
const paths = [];
3725

0 commit comments

Comments
 (0)