Skip to content

fix(shared): parse multi-line inline style #6777

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Nov 8, 2022
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 28 additions & 1 deletion packages/shared/__tests__/normalizeProp.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { normalizeClass } from '../src'
import { normalizeClass, parseStringStyle } from '../src'

describe('normalizeClass', () => {
test('handles string correctly', () => {
Expand All @@ -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",
}
`)
})
})
2 changes: 1 addition & 1 deletion packages/shared/src/normalizeProp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export function normalizeStyle(
}

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

export function parseStringStyle(cssText: string): NormalizedStyle {
const ret: NormalizedStyle = {}
Expand Down