Skip to content

Commit

Permalink
Correctly generate inline styles when they contain multiple colons (f…
Browse files Browse the repository at this point in the history
…ixes #9)
  • Loading branch information
peternewnham committed Aug 22, 2017
1 parent 37a317e commit e2b1ab6
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/utils/inlineStyleToObject.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,10 @@ export default function InlineStyleToObject(inlineStyle = '') {
(styleObject, stylePropertyValue) => {

// extract the style property name and value
let [property, value] = stylePropertyValue.split(':').map(item => item.trim().toLowerCase());
let [property, value] = stylePropertyValue
.split(/^([^:]+):/)
.filter((val, i) => i > 0)
.map(item => item.trim().toLowerCase());

// if there is no value (i.e. no : in the style) then ignore it
if (value === undefined) {
Expand Down
9 changes: 9 additions & 0 deletions test/unit/utils/inlineStyleToObject.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,13 @@ describe('Testing `utils/inlineStyleToObject', () => {
expect(inlineStyleToObject(inlineStyle)).toEqual(expectedStyleObject);
});

it('should parse styles containing multiple colons correctly', () => {
const inlineStyle = 'background:url(https://test.com/image.png);color:white;';
const expectedStyleObject = {
background: 'url(https://test.com/image.png)',
color: 'white'
};
expect(inlineStyleToObject(inlineStyle)).toEqual(expectedStyleObject);
});

});

0 comments on commit e2b1ab6

Please sign in to comment.