Skip to content

Commit

Permalink
fix(ssr): fix cachedEscape memory issue
Browse files Browse the repository at this point in the history
close #6332
  • Loading branch information
yyx990803 committed Sep 1, 2017
1 parent 50257a5 commit 02f8b80
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 12 deletions.
4 changes: 2 additions & 2 deletions src/platforms/web/server/modules/attrs.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* @flow */

import { cachedEscape } from '../util'
import { escape } from '../util'

import {
isDef,
Expand Down Expand Up @@ -50,7 +50,7 @@ export function renderAttr (key: string, value: string): string {
} else if (isEnumeratedAttr(key)) {
return ` ${key}="${isFalsyAttrValue(value) || value === 'false' ? 'false' : 'true'}"`
} else if (!isFalsyAttrValue(value)) {
return ` ${key}="${cachedEscape(String(value))}"`
return ` ${key}="${escape(String(value))}"`
}
return ''
}
4 changes: 2 additions & 2 deletions src/platforms/web/server/modules/class.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
/* @flow */

import { cachedEscape } from '../util'
import { escape } from '../util'
import { genClassForVnode } from 'web/util/index'

export default function renderClass (node: VNodeWithData): ?string {
const classList = genClassForVnode(node)
if (classList !== '') {
return ` class="${cachedEscape(classList)}"`
return ` class="${escape(classList)}"`
}
}
4 changes: 2 additions & 2 deletions src/platforms/web/server/modules/style.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* @flow */

import { cachedEscape } from '../util'
import { escape } from '../util'
import { hyphenate } from 'shared/util'
import { getStyle } from 'web/util/style'

Expand All @@ -23,6 +23,6 @@ export function genStyle (style: Object): string {
export default function renderStyle (vnode: VNodeWithData): ?string {
const styleText = genStyle(getStyle(vnode, false))
if (styleText !== '') {
return ` style=${JSON.stringify(cachedEscape(styleText))}`
return ` style=${JSON.stringify(escape(styleText))}`
}
}
4 changes: 1 addition & 3 deletions src/platforms/web/server/util.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* @flow */

import { makeMap, cached } from 'shared/util'
import { makeMap } from 'shared/util'

const isAttr = makeMap(
'accept,accept-charset,accesskey,action,align,alt,async,autocomplete,' +
Expand Down Expand Up @@ -46,8 +46,6 @@ export function escape (s: string) {
return s.replace(/[<>"&]/g, escapeChar)
}

export const cachedEscape = cached(escape)

function escapeChar (a) {
return ESC[a] || a
}
6 changes: 3 additions & 3 deletions src/server/optimizing-compiler/runtime-helpers.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* @flow */

import { escape, cachedEscape } from 'web/server/util'
import { escape } from 'web/server/util'
import { isObject, extend } from 'shared/util'
import { renderAttr } from 'web/server/modules/attrs'
import { renderClass } from 'web/util/class'
Expand Down Expand Up @@ -123,7 +123,7 @@ function renderSSRClass (
dynamic: any
): string {
const res = renderClass(staticClass, dynamic)
return res === '' ? res : ` class="${cachedEscape(res)}"`
return res === '' ? res : ` class="${escape(res)}"`
}

function renderSSRStyle (
Expand All @@ -136,5 +136,5 @@ function renderSSRStyle (
if (dynamic) extend(style, normalizeStyleBinding(dynamic))
if (extra) extend(style, extra)
const res = genStyle(style)
return res === '' ? res : ` style=${JSON.stringify(cachedEscape(res))}`
return res === '' ? res : ` style=${JSON.stringify(escape(res))}`
}

0 comments on commit 02f8b80

Please sign in to comment.