Browse Source

fix(ssr): fix double escaping of staticClass values (#7859) (#8037)

Haoqun Jiang 7 years ago
parent
commit
c21b89ebed
2 changed files with 15 additions and 1 deletions
  1. 1 1
      src/server/optimizing-compiler/modules.js
  2. 14 0
      test/ssr/ssr-string.spec.js

+ 1 - 1
src/server/optimizing-compiler/modules.js

@@ -92,7 +92,7 @@ export function genClassSegments (
   classBinding: ?string
 ): Array<StringSegment> {
   if (staticClass && !classBinding) {
-    return [{ type: RAW, value: ` class=${staticClass}` }]
+    return [{ type: RAW, value: ` class="${JSON.parse(staticClass)}"` }]
   } else {
     return [{
       type: EXPRESSION,

+ 14 - 0
test/ssr/ssr-string.spec.js

@@ -1245,6 +1245,20 @@ describe('SSR: renderToString', () => {
     })
   })
 
+  // #7859
+  it('should not double escape class values', done => {
+    renderVmWithOptions({
+      template: `
+      <div>
+        <div class="a\nb"></div>
+      </div>
+      `
+    }, result => {
+      expect(result).toContain(`<div class="a\nb"></div>`)
+      done()
+    })
+  })
+
   it('should expose ssr helpers on functional context', done => {
     let called = false
     renderVmWithOptions({