From 9768949ce0cbe91cffb708cf005807413d60c031 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=B8=89=E5=92=B2=E6=99=BA=E5=AD=90=20Kevin=20Deng?= Date: Tue, 8 Nov 2022 11:17:50 +0800 Subject: [PATCH] fix(shared): fix parsing of multi-line inline style (#6777) --- .../shared/__tests__/normalizeProp.spec.ts | 29 ++++++++++++++++++- packages/shared/src/normalizeProp.ts | 2 +- 2 files changed, 29 insertions(+), 2 deletions(-) diff --git a/packages/shared/__tests__/normalizeProp.spec.ts b/packages/shared/__tests__/normalizeProp.spec.ts index c884d9e7281..4ef69503f04 100644 --- a/packages/shared/__tests__/normalizeProp.spec.ts +++ b/packages/shared/__tests__/normalizeProp.spec.ts @@ -1,4 +1,4 @@ -import { normalizeClass } from '../src' +import { normalizeClass, parseStringStyle } from '../src' describe('normalizeClass', () => { test('handles string correctly', () => { @@ -16,4 +16,31 @@ describe('normalizeClass', () => { 'foo baz' ) }) + + // #6777 + test('parse multi-line inline style', () => { + expect( + parseStringStyle(`border: 1px solid transparent; + background: linear-gradient(white, white) padding-box, + repeating-linear-gradient( + -45deg, + #ccc 0, + #ccc 0.5em, + white 0, + white 0.75em + );`) + ).toMatchInlineSnapshot(` + Object { + "background": "linear-gradient(white, white) padding-box, + repeating-linear-gradient( + -45deg, + #ccc 0, + #ccc 0.5em, + white 0, + white 0.75em + )", + "border": "1px solid transparent", + } + `) + }) }) diff --git a/packages/shared/src/normalizeProp.ts b/packages/shared/src/normalizeProp.ts index 283309a4369..b4010eb6350 100644 --- a/packages/shared/src/normalizeProp.ts +++ b/packages/shared/src/normalizeProp.ts @@ -27,7 +27,7 @@ export function normalizeStyle( } const listDelimiterRE = /;(?![^(]*\))/g -const propertyDelimiterRE = /:(.+)/ +const propertyDelimiterRE = /:([^]+)/ export function parseStringStyle(cssText: string): NormalizedStyle { const ret: NormalizedStyle = {}