Selaa lähdekoodia

use cheaper escape

Evan You 9 vuotta sitten
vanhempi
commit
c0b9b6d830

+ 1 - 1
src/platforms/web/server/modules/attrs.js

@@ -1,6 +1,6 @@
 /* @flow */
 
-import { escape } from 'he'
+import { escape } from '../util'
 
 import {
   isDef,

+ 1 - 1
src/platforms/web/server/modules/class.js

@@ -1,6 +1,6 @@
 /* @flow */
 
-import { escape } from 'he'
+import { escape } from '../util'
 import { genClassForVnode } from 'web/util/index'
 
 export default function renderClass (node: VNodeWithData): ?string {

+ 1 - 1
src/platforms/web/server/modules/style.js

@@ -1,6 +1,6 @@
 /* @flow */
 
-import { escape } from 'he'
+import { escape } from '../util'
 import { hyphenate } from 'shared/util'
 import { getStyle } from 'web/util/style'
 

+ 15 - 0
src/platforms/web/server/util.js

@@ -34,3 +34,18 @@ export const propsToAttrMap = {
   htmlFor: 'for',
   httpEquiv: 'http-equiv'
 }
+
+const ESC = {
+  '<': '&lt;',
+  '>': '&gt;',
+  '"': '&quot;',
+  '&': '&amp;'
+}
+
+export function escape (s: string) {
+  return s.replace(/[<>"&]/g, escapeChar)
+}
+
+function escapeChar (a) {
+  return ESC[a] || a
+}

+ 1 - 1
src/server/optimizing-compiler/runtime-helpers.js

@@ -1,6 +1,6 @@
 /* @flow */
 
-import { escape } from 'he'
+import { escape } from 'web/server/util'
 import { isObject } from 'shared/util'
 import { renderAttr } from 'web/server/modules/attrs'
 import { renderClass } from 'web/util/class'

+ 1 - 2
src/server/render.js

@@ -1,7 +1,6 @@
 /* @flow */
 
-const { escape } = require('he')
-
+import { escape } from 'web/server/util'
 import { SSR_ATTR } from 'shared/constants'
 import { RenderContext } from './render-context'
 import { ssrCompileToFunctions } from 'web/server/compiler'