Cesium3DTileStyle string variables substitution sometimes fails #12455
Labels
category - architecture / api
good first issue
An opportunity for first time contributors
type - bug
What happened?
Substitution of variables in Cesium Scene Expression _evaluateVariableString not always substitute all the templates
cesium/packages/engine/Source/Scene/Expression.js
Lines 1217 to 1231 in 4e6dde5
Current version uses regex stored in a global variable. In JavaScript regular expression objects are statefull and _evaluateVariableString changes the regexp input string not accounting for regexp object state.
variableRegex
keepslastIndex
that lead to an error in following scenario:lastIndex
would point 1 position after variable template)lastIndex
will point further in rewritten stringlastIndex
now points after$
sign for second variable template, match will fail and value won't be substituted.One way to fix it would be to account for result string change in length after the replacement.
Here is a patch (for whatever reason it fails to upload as a separate file)
There is a stack overflow question describing how state in JavaScript regexp works https://stackoverflow.com/questions/11477415/why-does-javascripts-regex-exec-not-always-return-the-same-value
Reproduction steps
...
Sandcastle example
No response
Environment
Browser: Firefox
CesiumJS Version: 1.124 1.125
Operating System: Linux Mint
The text was updated successfully, but these errors were encountered: