Skip to content

fix(7986): nested css-calc and css-variables with fallback give incorrect result - #7987

Merged
manoldonev merged 5 commits into
NativeScript:masterfrom
m-abs:fix/nested-css-calc-variable-broken
Nov 7, 2019
Merged

manoldonev merged 5 commits into
NativeScript:masterfrom
m-abs:fix/nested-css-calc-variable-broken

Conversation

@m-abs

@m-abs m-abs commented Oct 21, 2019

Copy link
Copy Markdown
Contributor

PR Checklist

What is the current behavior?

Nesting css-calc expressions with css-variable with fallback give the wrong result.

Assuming input value: calc(calc(var(--undefined-var, 16) / 2) * 2).

  1. _evaluateCssVariableExpression returns calc(calc(16) / 2) * 2) (note: the missing end-))
  2. _evaluateCssCalcExpression returns 8 * 2).
  3. Then the value is cast to number with parseFloat which results in the number 8.

The problem is caused by cssVariableExpressionRegexp finding the wrong ).

What is the new behavior?

Fixes #7986.

  1. No longer uses regexp to process css-variable expressions.
  2. Switch to simple string operations e.g. includes, indexOf and lastIndexOf.
  3. Process css-variable expressions is now done from the end of the string, before it was done from the start.
    3b. This means the inner css-variable is a nested expression is processed first, but this was the simplest way to find the correct end-) of those expressions.

@cla-bot cla-bot Bot added the cla: yes label Oct 21, 2019
@manoldonev

Copy link
Copy Markdown
Contributor

test

@manoldonev
manoldonev merged commit fc2a233 into NativeScript:master Nov 7, 2019
@m-abs
m-abs deleted the fix/nested-css-calc-variable-broken branch November 27, 2019 20:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

nested css-calc and css-variables with fallback give incorrect result

2 participants