MCPcopy
hub / github.com/vuejs/core / escapeHtml

Function escapeHtml

packages/shared/src/escapeHtml.ts:3–45  ·  view source on GitHub ↗
(string: unknown)

Source from the content-addressed store, hash-verified

1const escapeRE = /["'&<>]/
2
3export function escapeHtml(string: unknown): string {
4 const str = '' + string
5 const match = escapeRE.exec(str)
6
7 if (!match) {
8 return str
9 }
10
11 let html = ''
12 let escaped: string
13 let index: number
14 let lastIndex = 0
15 for (index = match.index; index < str.length; index++) {
16 switch (str.charCodeAt(index)) {
17 case 34: // "
18 escaped = '&quot;'
19 break
20 case 38: // &
21 escaped = '&amp;'
22 break
23 case 39: // '
24 escaped = '&#39;'
25 break
26 case 60: // <
27 escaped = '&lt;'
28 break
29 case 62: // >
30 escaped = '&gt;'
31 break
32 default:
33 continue
34 }
35
36 if (lastIndex !== index) {
37 html += str.slice(lastIndex, index)
38 }
39
40 lastIndex = index + 1
41 html += escaped
42 }
43
44 return lastIndex !== index ? html + str.slice(lastIndex, index) : html
45}
46
47// https://www.w3.org/TR/html52/syntax.html#comments
48const commentStripRE = /^-?>|<!--|-->|--!>|<!-$/g

Callers 15

processChildrenFunction · 0.90
ssrTransformElementFunction · 0.90
escapeHtml.spec.tsFile · 0.90
stringifyNodeFunction · 0.90
stringifyElementFunction · 0.90
renderVNodeFunction · 0.90
renderElementVNodeFunction · 0.90
ssrInterpolateFunction · 0.90
ssrRenderAttrsFunction · 0.90
ssrRenderDynamicAttrFunction · 0.90
ssrRenderAttrFunction · 0.90
ssrRenderClassFunction · 0.90

Calls

no outgoing calls

Tested by 1

testRenderFunction · 0.72