Skip to content

Commit

Permalink
Fix style values containing upper-case characters
Browse files Browse the repository at this point in the history
  • Loading branch information
zhangbenber committed Mar 23, 2021
1 parent e89bba4 commit 1a64a90
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/utils/inlineStyleToObject.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export default function InlineStyleToObject(inlineStyle = '') {
let [property, value] = stylePropertyValue
.split(/^([^:]+):/)
.filter((val, i) => i > 0)
.map(item => item.trim().toLowerCase());
.map(item => item.trim());

// if there is no value (i.e. no : in the style) then ignore it
if (value === undefined) {
Expand All @@ -33,6 +33,7 @@ export default function InlineStyleToObject(inlineStyle = '') {
// e.g. -ms-style-property = msStyleProperty
// -webkit-style-property = WebkitStyleProperty
property = property
.toLowerCase()
.replace(/^-ms-/, 'ms-')
.replace(/-(.)/g, (_, character) => character.toUpperCase());

Expand Down
8 changes: 8 additions & 0 deletions test/unit/utils/inlineStyleToObject.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,4 +42,12 @@ describe('Testing `utils/inlineStyleToObject', () => {
expect(inlineStyleToObject(inlineStyle)).toEqual(expectedStyleObject);
});

it('should parse style values containing upper-case characters correctly', () => {
const inlineStyle = 'background:url(https://test.com/IMAGE.png);';
const expectedStyleObject = {
background: 'url(https://test.com/IMAGE.png)',
};
expect(inlineStyleToObject(inlineStyle)).toEqual(expectedStyleObject);
});

});

0 comments on commit 1a64a90

Please sign in to comment.