Bug 161271 - calc(): + and - with one operand of unitless length 0 and another of a length with explicit units are incorrectly ignored as invalid
Summary: calc(): + and - with one operand of unitless length 0 and another of a length...
Status: RESOLVED INVALID
Alias: None
Product: WebKit
Classification: Unclassified
Component: CSS (show other bugs)
Version: WebKit Nightly Build
Hardware: Unspecified Unspecified
: P2 Normal
Assignee: Nobody
URL: http://jsbin.com/jejewa/1/edit?html,o...
Keywords:
Depends on:
Blocks:
 
Reported: 2016-08-26 15:23 PDT by Russell Bicknell
Modified: 2016-10-11 13:12 PDT (History)
3 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Russell Bicknell 2016-08-26 15:23:45 PDT
Example URL:
http://jsbin.com/jejewa/1/edit?html,output

Steps to reproduce the problem:
Write a CSS rule using `calc()` to produce a length and add unitless zero to that length within the `calc()`. For example, `calc(1px + 0)`. The rule will be considered invalid.

What is the expected behavior?
Unitless zero is a valid length (https://www.w3.org/TR/css-values/#lengths, https://drafts.csswg.org/css-values-3/#lengths) so adding and subtracting unitless zero and other lengths with explicit units should resolve to the type of unit of the other operand.

One specific problem this bug results in is when using `calc()` with CSS custom properties. If you write a `calc()` function using a custom property as an operand to an addition or subtraction with a length, the person setting the value of that custom property you've provided can't use the unitless zero shorthand even though it is a valid length.

What went wrong?
Safari (and all other browsers I tested) report this kind of expression as invalid and ignore it.

Also filed against Chrome:
https://bugs.chromium.org/p/chromium/issues/detail?id=641556
Comment 1 Russell Bicknell 2016-10-11 13:12:25 PDT
This behavior has been deemed correct by the spec author.