Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit f713b4f

Browse filesBrowse files
committed
propValue.trim() sometimes causes TypeError
1 parent 890f821 commit f713b4f
Copy full SHA for f713b4f

File tree

Expand file treeCollapse file tree

2 files changed

+15
-4
lines changed
Filter options
Expand file treeCollapse file tree

2 files changed

+15
-4
lines changed

‎src/get-props-from-attributes.js

Copy file name to clipboardExpand all lines: src/get-props-from-attributes.js
+2-3Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,11 @@ function getStylePropValue (attrValue) {
3030
})
3131

3232
return props.reduce((props, prop) => {
33-
let [propName, propValue] = prop.split(/:(.+)?/)
33+
let [propName, propValue] = prop.split(/:/)
3434
propName = formatStylePropName(propName)
35-
propValue = propValue.trim()
3635
return {
3736
...props,
38-
[propName]: propValue
37+
[propName]: propValue && propValue.trim(),
3938
}
4039
}, {})
4140
}

‎test/get-props-from-attributes.test.js

Copy file name to clipboardExpand all lines: test/get-props-from-attributes.test.js
+13-1Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,19 @@ it("gets props from <span style='...'/> element", () => {
4444
.toEqual({
4545
style: {
4646
color: 'red',
47-
fontWeight: 'bold'
47+
fontWeight: 'bold',
48+
},
49+
});
50+
});
51+
52+
it("works with invalid styles", () => {
53+
const element = toElement('<span style="color:;font-size">foo</span>');
54+
55+
expect(getPropsFromAttributes(element))
56+
.toEqual({
57+
style: {
58+
color: '',
59+
fontSize: undefined,
4860
},
4961
});
5062
});

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.