Skip to content

Commit 3581a92

Browse files
committed
Merge pull request #1642 from ryanseddon/trimCSSValues
Correctly trim strings for css properties
2 parents 295da0a + 2bff5c5 commit 3581a92

File tree

2 files changed

+11
-0
lines changed

2 files changed

+11
-0
lines changed

src/browser/ui/dom/__tests__/CSSPropertyOperations-test.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,14 @@ describe('CSSPropertyOperations', function() {
6868
})).toBe('left:0;margin:16px;opacity:0.5;padding:4px;');
6969
});
7070

71+
it('should trim values so `px` will be appended correctly', function() {
72+
expect(CSSPropertyOperations.createMarkupForStyles({
73+
margin: '16 ',
74+
opacity: 0.5,
75+
padding: ' 4 '
76+
})).toBe('margin:16px;opacity:0.5;padding:4px;');
77+
});
78+
7179
it('should not append `px` to styles that might need a number', function() {
7280
var CSSProperty = require('CSSProperty');
7381
var unitlessProperties = Object.keys(CSSProperty.isUnitlessNumber);

src/browser/ui/dom/dangerousStyleValue.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,9 @@ function dangerousStyleValue(name, value) {
5454
return '' + value; // cast to string
5555
}
5656

57+
if (typeof value === 'string') {
58+
value = value.trim();
59+
}
5760
return value + 'px';
5861
}
5962

0 commit comments

Comments
 (0)