Bug 218295 - Web Inspector: Extra closing parenthesis added after var in styles panel
Summary: Web Inspector: Extra closing parenthesis added after var in styles panel
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: Web Inspector (show other bugs)
Version: Safari 13
Hardware: All All
: P2 Normal
Assignee: Nikita Vasilyev
URL:
Keywords: InRadar
Depends on:
Blocks:
 
Reported: 2020-10-28 11:00 PDT by Zach Bjornson
Modified: 2020-10-30 11:06 PDT (History)
5 users (show)

See Also:


Attachments
WIP (2.76 KB, patch)
2020-10-28 17:58 PDT, Nikita Vasilyev
nvasilyev: commit-queue-
Details | Formatted Diff | Diff
Patch (2.75 KB, patch)
2020-10-29 15:38 PDT, Nikita Vasilyev
no flags Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Zach Bjornson 2020-10-28 11:00:56 PDT
Given a rule like:

.class {
  --my-var: calc(var(--other-var) * 1em);
}

The Styles panel adds an extra closing parenthesis, making it look like:

  --my-var: calc(var(--other-var)) * 1em);  

Tested in Safari 13.1.2.
Comment 1 Nikita Vasilyev 2020-10-28 11:02:21 PDT
Thank you for reporting, I'll look into this.
Comment 2 Radar WebKit Bug Importer 2020-10-28 11:02:58 PDT
<rdar://problem/70771314>
Comment 3 Nikita Vasilyev 2020-10-28 16:13:54 PDT
WI.SpreadsheetStyleProperty.prototype._addVariableTokens(tokens) returns an array of tokens with an extra closed parenthesis.
Comment 4 Nikita Vasilyev 2020-10-28 17:58:52 PDT
Created attachment 412596 [details]
WIP

This fixes the bug. However, this method is pretty error prone and could really benefit from unit tests. I'm planning to move it outside of the Views.
Comment 5 Devin Rousso 2020-10-29 12:02:24 PDT
Comment on attachment 412596 [details]
WIP

View in context: https://bugs.webkit.org/attachment.cgi?id=412596&action=review

> Source/WebInspectorUI/UserInterface/Views/SpreadsheetStyleProperty.js:-826
> -                        contents.pushAll(rawTokens.slice(variableNameIndex + 1, i));

We also probably should remove the `, i` above too.  Using `i` is incorrect because `rawTokens` is not the same length as `tokens` :/

> Source/WebInspectorUI/UserInterface/Views/SpreadsheetStyleProperty.js:-827
> -                    contents.push(token);

I think this was ultimately the issue (i.e. you could leave the `i + 1` as is above).
Comment 6 Nikita Vasilyev 2020-10-29 14:08:23 PDT
Comment on attachment 412596 [details]
WIP

View in context: https://bugs.webkit.org/attachment.cgi?id=412596&action=review

>> Source/WebInspectorUI/UserInterface/Views/SpreadsheetStyleProperty.js:-826
>> -                        contents.pushAll(rawTokens.slice(variableNameIndex + 1, i));
> 
> We also probably should remove the `, i` above too.  Using `i` is incorrect because `rawTokens` is not the same length as `tokens` :/

You mean on the line 817, right? Yes, it shouldn't be used there.
And yes, that's why I'm removing `, i`.

>> Source/WebInspectorUI/UserInterface/Views/SpreadsheetStyleProperty.js:-827
>> -                    contents.push(token);
> 
> I think this was ultimately the issue (i.e. you could leave the `i + 1` as is above).

My change on line 793 alone fixes this bug. At the same time, all the changes in this patch but on the line 793 fixes the bug, too :)
However, keeping the ")" at the end of rawTokens isn't used for anything, and is a footgun.
Comment 7 Nikita Vasilyev 2020-10-29 15:37:39 PDT
Comment on attachment 412596 [details]
WIP

View in context: https://bugs.webkit.org/attachment.cgi?id=412596&action=review

>>> Source/WebInspectorUI/UserInterface/Views/SpreadsheetStyleProperty.js:-827
>>> -                    contents.push(token);
>> 
>> I think this was ultimately the issue (i.e. you could leave the `i + 1` as is above).
> 
> My change on line 793 alone fixes this bug. At the same time, all the changes in this patch but on the line 793 fixes the bug, too :)
> However, keeping the ")" at the end of rawTokens isn't used for anything, and is a footgun.

Actually, I see rawTokens is being used in fallbackTokens, which is passed to the rest of _add*Tokens function. I'll take your suggestion and leave it as-is.
"At the same time, all the changes in this patch but on the line 793 fixes the bug, too :)" — this statement was incorrect :/
Comment 8 Nikita Vasilyev 2020-10-29 15:38:53 PDT
Created attachment 412694 [details]
Patch

Now it's a really tiny patch ☺️
Comment 9 Devin Rousso 2020-10-30 10:15:43 PDT
Comment on attachment 412694 [details]
Patch

r=me
Comment 10 EWS 2020-10-30 11:06:33 PDT
Committed r269201: <https://trac.webkit.org/changeset/269201>

All reviewed patches have been landed. Closing bug and clearing flags on attachment 412694 [details].