diff --git a/src/browser/ui/dom/__tests__/CSSPropertyOperations-test.js b/src/browser/ui/dom/__tests__/CSSPropertyOperations-test.js index b40617f743..77e9e5f6cf 100644 --- a/src/browser/ui/dom/__tests__/CSSPropertyOperations-test.js +++ b/src/browser/ui/dom/__tests__/CSSPropertyOperations-test.js @@ -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); diff --git a/src/browser/ui/dom/dangerousStyleValue.js b/src/browser/ui/dom/dangerousStyleValue.js index 44cbe8166d..c1108ce23e 100644 --- a/src/browser/ui/dom/dangerousStyleValue.js +++ b/src/browser/ui/dom/dangerousStyleValue.js @@ -54,6 +54,9 @@ function dangerousStyleValue(name, value) { return '' + value; // cast to string } + if (typeof value === 'string') { + value = value.trim(); + } return value + 'px'; }