Merge pull request #1642 from ryanseddon/trimCSSValues

Correctly trim strings for css properties
This commit is contained in:
Paul O’Shannessy
2014-06-25 22:02:54 -07:00
2 changed files with 11 additions and 0 deletions
@@ -68,6 +68,14 @@ describe('CSSPropertyOperations', function() {
})).toBe('left:0;margin:16px;opacity:0.5;padding:4px;');
});
it('should trim values so `px` will be appended correctly', function() {
expect(CSSPropertyOperations.createMarkupForStyles({
margin: '16 ',
opacity: 0.5,
padding: ' 4 '
})).toBe('margin:16px;opacity:0.5;padding:4px;');
});
it('should not append `px` to styles that might need a number', function() {
var CSSProperty = require('CSSProperty');
var unitlessProperties = Object.keys(CSSProperty.isUnitlessNumber);
@@ -54,6 +54,9 @@ function dangerousStyleValue(name, value) {
return '' + value; // cast to string
}
if (typeof value === 'string') {
value = value.trim();
}
return value + 'px';
}