-
Notifications
You must be signed in to change notification settings - Fork 1.7k
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
fixed getStyleObjectFromRawCSS to handle css values with a colon #2814
fixed getStyleObjectFromRawCSS to handle css values with a colon #2814
Conversation
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
Nice, thanks for writing a test! |
const patch = style.split(':'); | ||
styleObject[patch[0].trim()] = patch[1].trim(); | ||
const [key, ...value] = style.split(':'); | ||
styleObject[key.trim()] = value.join(':').trim(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess another way to go at this would be Regex capture groups, which might be more performant than all this string manipulation. Thoughts?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
im not great with regex but gave it a go - lmk what you think
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great catch, the regex version looks much cleaner!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks right to me, pending CI pass
@@ -310,8 +310,8 @@ function getStyleObjectFromRawCSS(css: string): Record<string, string> { | |||
|
|||
for (const style of styles) { | |||
if (style !== '') { | |||
const patch = style.split(':'); | |||
styleObject[patch[0].trim()] = patch[1].trim(); | |||
const [key, value] = style.split(/:([^]+)/); // split on first colon |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I had actually forgotten you could use the "^" character this way in JS RegEx!
* fixed getStyleObjectFromRawCSS to handle css values with a colon * use regex instead of string manipulation * add test cases * prettier formatting
Currently if a css property has a colon in its value the rest of the value following the colon gets cut off.
Ran into this when using a font family with a prefix e.g.
font-family: prefix:Arial