Closed Bug 1462553 Opened 6 years ago Closed 6 years ago

Use of !important before the end of a value is wrongly considered valid in the rule-view

Categories

(DevTools :: Inspector: Rules, defect, P2)

defect

Tracking

(firefox62 fixed)

RESOLVED FIXED
Firefox 62
Tracking Status
firefox62 --- fixed

People

(Reporter: pbro, Assigned: tromey)

References

()

Details

(Whiteboard: [good first verify] [bugday-20180718])

Attachments

(1 file)

STR:

- open the following test page in a tab:
data:text/html,<style>body{background: !important blue;}</style>
- notice that the background is white, because the background value is invalid
- open the inspector and look at the Rules view.

Expected:
it should display background: !important blue; exactly and mark it as invalid

Actual:
it displays background: blue !important;  and thinks it's valid.
I investigated a little bit and found the root cause to be in 
/devtools/shared/css/parsing-utils.js
in the parseDeclarationsInternal function.

Somewhere in there, when we find a ! token, then we remember that we've seen it, then later, when we find an important ident, we set the priority of the declaration to important.
However we do regardless of the position of these things. So if they appear at the start of the value, the declaration is still marked as important.

I believe !important only ever works when it appears as the very last part of a value.
From the cascade spec [1]: "the delimiter token "!" and keyword "important" follow the declaration".
That means they need to appear at the end of the declaration. Note that there can be spaces/tabs between ! and important.

[1] https://www.w3.org/TR/CSS2/cascade.html#important-rules
Adding something like this inside this function's while loop:
const isLastToken = !inputString.substring(token.endOffset).trim();
and then using it later to condition adding the important state to the declaration would work I think.
I have a patch.
Assignee: nobody → ttromey
Comment on attachment 8977075 [details]
Bug 1462553 - fix !important parsing in devtools;

https://reviewboard.mozilla.org/r/245150/#review251322

Thank you Tom!

::: devtools/shared/css/parsing-utils.js:386
(Diff revision 1)
> -        if (hasBang) {
> +        if (importantState === 1) {
>            current += "!";
> +          importantState = 0;
> +        } else if (importantState === 2) {
> +          // The "!important" is no longer valid.
> +          current += "!important ";

Do we care about preserving potential spaces between ! and important? 
The current patch doesn't.

So, something like this:
p:    !     important v;

will produce
p:    !important v;

If this is hard to fix, I don't think we should care too much. In fact I'll R+ the patch with this because this is probably never going to occur.
But just curious.

::: devtools/shared/css/parsing-utils.js:419
(Diff revision 1)
> +      if (importantState === 1) {
> +        current += "!";
> +        importantState = 0;
> +      } else if (importantState === 2) {
> +        // The !important is no longer valid.
> +        current += "!important ";

Same comment here.
Attachment #8977075 - Flags: review?(pbrosset) → review+
(In reply to Patrick Brosset <:pbro> from comment #6)

> Do we care about preserving potential spaces between ! and important? 
> The current patch doesn't.

I'll take a look to see how hard it would be.
I suppose it's just one more state in the state machine.

It's maybe worth noting that we don't really try to faithfully preserve whitespace
here already.  Multiple spaces and comments are collapsed to a single space.
Pushed by ttromey@mozilla.com:
https://hg.mozilla.org/integration/autoland/rev/cbb0b27b6e59
fix !important parsing in devtools; r=pbro
I pushed it with (some) whitespace preservation.
https://hg.mozilla.org/mozilla-central/rev/cbb0b27b6e59
Status: NEW → RESOLVED
Closed: 6 years ago
Resolution: --- → FIXED
Target Milestone: --- → Firefox 62
Product: Firefox → DevTools
Whiteboard: [good first verify]
I have reproduced this bug with Nightly 62.0a1 (2018-05-18) on Windows 10, 64 Bit!
This bug's fix is verified with latest Beta!

Build ID 	20180713213322
User Agent 	Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:62.0) Gecko/20100101 Firefox/62.0
Whiteboard: [good first verify] → [good first verify] [bugday-20180718]
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: