Skip to content

Commit b443817

Browse files
committed
fix(compiler-vapor): encode quotes back
1 parent 0be562e commit b443817

File tree

3 files changed

+73
-4
lines changed

3 files changed

+73
-4
lines changed

packages/compiler-vapor/__tests__/transforms/__snapshots__/transformElement.spec.ts.snap

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -399,7 +399,37 @@ export function render(_ctx) {
399399
400400
exports[`compiler: element transform > static props 1`] = `
401401
"import { template as _template } from 'vue';
402-
const t0 = _template("<div id=foo class=bar title=\\"has whitespace\\"data-targets=\\"foo>bar\\"></div>", true)
402+
const t0 = _template("<div id=foo class=bar></div>", true)
403+
404+
export function render(_ctx) {
405+
const n0 = t0()
406+
return n0
407+
}"
408+
`;
409+
410+
exports[`compiler: element transform > static props mixed quoting 1`] = `
411+
"import { template as _template } from 'vue';
412+
const t0 = _template("<div title=\\"has whitespace\\"inert data-targets=\\"foo>bar\\"></div>", true)
413+
414+
export function render(_ctx) {
415+
const n0 = t0()
416+
return n0
417+
}"
418+
`;
419+
420+
exports[`compiler: element transform > static props quoted 1`] = `
421+
"import { template as _template } from 'vue';
422+
const t0 = _template("<div title=\\"has whitespace\\"alt=\\"&#34;contains quotes&#34;\\"data-targets=\\"foo>bar\\"></div>", true)
423+
424+
export function render(_ctx) {
425+
const n0 = t0()
426+
return n0
427+
}"
428+
`;
429+
430+
exports[`compiler: element transform > static props unquoted 1`] = `
431+
"import { template as _template } from 'vue';
432+
const t0 = _template("<div id=foo class=bar title=foo\\"=bar></div>", true)
403433
404434
export function render(_ctx) {
405435
const n0 = t0()

packages/compiler-vapor/__tests__/transforms/transformElement.spec.ts

Lines changed: 39 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -573,11 +573,48 @@ describe('compiler: element transform', () => {
573573

574574
test('static props', () => {
575575
const { code, ir } = compileWithElementTransform(
576-
`<div id="foo" class="bar" title="has whitespace" inert data-targets="foo>bar" />`,
576+
`<div id="foo" class="bar" />`,
577+
)
578+
579+
const template = '<div id=foo class=bar></div>'
580+
expect(code).toMatchSnapshot()
581+
expect(code).contains(JSON.stringify(template))
582+
expect(ir.template).toMatchObject([template])
583+
expect(ir.block.effect).lengthOf(0)
584+
})
585+
586+
test('static props unquoted', () => {
587+
const { code, ir } = compileWithElementTransform(
588+
`<div id="foo" class="bar" title='foo"=bar' />`,
589+
)
590+
591+
const template = '<div id=foo class=bar title=foo"=bar></div>'
592+
expect(code).toMatchSnapshot()
593+
expect(code).contains(JSON.stringify(template))
594+
expect(ir.template).toMatchObject([template])
595+
expect(ir.block.effect).lengthOf(0)
596+
})
597+
598+
test('static props quoted', () => {
599+
const { code, ir } = compileWithElementTransform(
600+
`<div title="has whitespace" alt='"contains quotes"' data-targets="foo>bar" />`,
601+
)
602+
603+
const template =
604+
'<div title="has whitespace"alt="&#34;contains quotes&#34;"data-targets="foo>bar"></div>'
605+
expect(code).toMatchSnapshot()
606+
expect(code).contains(JSON.stringify(template))
607+
expect(ir.template).toMatchObject([template])
608+
expect(ir.block.effect).lengthOf(0)
609+
})
610+
611+
test('static props mixed quoting', () => {
612+
const { code, ir } = compileWithElementTransform(
613+
`<div title="has whitespace" inert data-targets="foo>bar" />`,
577614
)
578615

579616
const template =
580-
'<div id=foo class=bar title="has whitespace"inert data-targets="foo>bar"></div>'
617+
'<div title="has whitespace"inert data-targets="foo>bar"></div>'
581618
expect(code).toMatchSnapshot()
582619
expect(code).contains(JSON.stringify(template))
583620
expect(ir.template).toMatchObject([template])

packages/compiler-vapor/src/transforms/transformElement.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -236,7 +236,9 @@ function transformNativeElement(
236236
needsQuoting = /[\s>]|^["'=]/.test(value)
237237

238238
if (needsQuoting) {
239-
template += `="${value}"`
239+
const encoded = value.replace(/"/g, '&#34;')
240+
241+
template += `="${encoded}"`
240242
} else {
241243
template += `=${value}`
242244
}

0 commit comments

Comments
 (0)