Correctly trim strings for css properties
* If a unitless value is passed with a space it'll return `1 px`
Ryan Seddon committed
Jun 4, 2014 at 20:50 UTC
2bff5c5c7e776a183ed9b429f2cb46cc044d9bc1
2 files changed
+11
src/browser/ui/dom/__tests__/CSSPropertyOperations-test.js
+8
@@ -68,6 +68,14 @@ describe('CSSPropertyOperations', function() {
68
})).toBe('left:0;margin:16px;opacity:0.5;padding:4px;');
69
});
70
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
+
79
it('should not append `px` to styles that might need a number', function() {
80
var CSSProperty = require('CSSProperty');
81
var unitlessProperties = Object.keys(CSSProperty.isUnitlessNumber);
src/browser/ui/dom/dangerousStyleValue.js
+3
@@ -54,6 +54,9 @@ function dangerousStyleValue(name, value) {
54
return '' + value; // cast to string
55
}
56
57
+ if (typeof value === 'string') {
58
+ value = value.trim();
59
+ }
60
return value + 'px';
61
}
62