Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prevents adding units to css custom properties #9966

Merged
merged 6 commits into from
Jun 14, 2017
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion src/renderers/dom/shared/CSSPropertyOperations.js
Original file line number Diff line number Diff line change
Expand Up @@ -230,15 +230,17 @@ var CSSPropertyOperations = {
if (__DEV__) {
warnValidStyle(styleName, styles[styleName], component);
}
var isCustomProperty = styleName.indexOf('--') === 0;
var styleValue = dangerousStyleValue(
styleName,
styles[styleName],
component,
isCustomProperty,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not the only place this function is called as far as I can see. Can you please make sure this argument always exists?

);
if (styleName === 'float') {
styleName = 'cssFloat';
}
if (styleName.indexOf('--') === 0) {
if (isCustomProperty) {
style.setProperty(styleName, styleValue);
} else if (styleValue) {
style[styleName] = styleValue;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,7 @@ describe('CSSPropertyOperations', () => {
it('should not add units to CSS custom properties', () => {
class Comp extends React.Component {
render() {
return <div style={{ '--foo': 5 }} />;
return <div style={{'--foo': 5}} />;
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/renderers/dom/shared/dangerousStyleValue.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ var isUnitlessNumber = CSSProperty.isUnitlessNumber;
* @param {ReactDOMComponent} component
* @return {string} Normalized style value with dimensions applied.
*/
function dangerousStyleValue(name, value, component) {
function dangerousStyleValue(name, value, component, isCustomProperty) {
// Note that we've removed escapeTextForBrowser() calls here since the
// whole string will be escaped when the attribute is injected into
// the markup. If you provide unsafe user data here they can inject
Expand All @@ -42,7 +42,7 @@ function dangerousStyleValue(name, value, component) {
}

if (
name.indexOf('--') !== 0 &&
!isCustomProperty &&
typeof value === 'number' &&
value !== 0 &&
!(isUnitlessNumber.hasOwnProperty(name) && isUnitlessNumber[name])
Expand Down