Skip to content

Commit

Permalink
fix(compiler/runtime-dom): ignore comments in inline styles (#6808)
Browse files Browse the repository at this point in the history
fix #6807
  • Loading branch information
rudyxu1102 committed Nov 8, 2022
1 parent 1c292e1 commit 50e2253
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 6 deletions.
16 changes: 16 additions & 0 deletions packages/compiler-sfc/__tests__/compileTemplate.spec.ts
Expand Up @@ -22,6 +22,22 @@ test('should work', () => {
expect(result.code).toMatch(`export function render(`)
})

// #6807
test('should work with style comment', () => {
const source = `
<div style="
/* nothing */
width: 300px;
height: 100px/* nothing */
">{{ render }}</div>
`

const result = compile({ filename: 'example.vue', source })
expect(result.errors.length).toBe(0)
expect(result.source).toBe(source)
expect(result.code).toMatch(`{"width":"300px","height":"100px"}`)
})

test('preprocess pug', () => {
const template = parse(
`
Expand Down
16 changes: 10 additions & 6 deletions packages/shared/src/normalizeProp.ts
Expand Up @@ -28,15 +28,19 @@ export function normalizeStyle(

const listDelimiterRE = /;(?![^(]*\))/g
const propertyDelimiterRE = /:([^]+)/
const styleCommentRE = /\/\*.*?\*\//gs

This comment has been minimized.

Copy link
@diachedelic

diachedelic Jan 30, 2023

Is the sticky flag necessary here?


export function parseStringStyle(cssText: string): NormalizedStyle {
const ret: NormalizedStyle = {}
cssText.split(listDelimiterRE).forEach(item => {
if (item) {
const tmp = item.split(propertyDelimiterRE)
tmp.length > 1 && (ret[tmp[0].trim()] = tmp[1].trim())
}
})
cssText
.replace(styleCommentRE, '')
.split(listDelimiterRE)
.forEach(item => {
if (item) {
const tmp = item.split(propertyDelimiterRE)
tmp.length > 1 && (ret[tmp[0].trim()] = tmp[1].trim())
}
})
return ret
}

Expand Down

0 comments on commit 50e2253

Please sign in to comment.