Repository navigation
fix(format): replace every occurrence of a variable in string formatter templates. close #21843 - #21844
Open
0z5a wants to merge 1 commit into
Open
fix(format): replace every occurrence of a variable in string formatter templates. close #21843#218440z5a wants to merge 1 commit into
0z5a wants to merge 1 commit into
Conversation
…er templates
formatTpl and formatTplSimple used String.prototype.replace with a string
pattern, which only replaces the first match, so a template that uses
the same variable twice (e.g. '{b}: {c} | {b}: {c}') kept the second
copy as literal text. Replace all occurrences with a split/join helper
that inserts the value literally.
|
Thanks for your contribution! Please DO NOT commit the files in dist, i18n, and ssr/client/dist folders in a non-release pull request. These folders are for release use only. |
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Brief Information
This pull request is in the type of:
What does this PR do?
Makes
formatTplandformatTplSimplereplace every occurrence of a template variable, not only the first one.Fixed issues
{a}/{b}/{c}#21843: String formatter templates only replace the first occurrence of{a}/{b}/{c}Details
Before: What was the problem?
formatTplusedtpl.replace(string, value), which only replaces the first match. A label formatter such as'{b}: {c} | {b}: {c}'renderedMon: 120 | {b}: {c}, and multi-series templates that repeat{a0}/{c1}kept the later copies as literal text.formatTplSimple(calendar and matrix label formatters) had the same problem.{@xxx}dimension variables and time axis tokens were already replaced at every occurrence.After: How does it behave after the fixing?
Both functions use a small
replaceAllhelper (str.split(search).join(value + '')), so'{b}: {c} | {b}: {c}'rendersMon: 120 | Mon: 120. The inserted value stays literal, so$sequences in names are still kept as they are (same result as #21751). Unknown variables and out-of-range series indexes are left unchanged, as before.Document Info
One of the following should be checked.
Misc
Security Checking
ZRender Changes
Related test cases or examples to use the new APIs
test/ut/spec/util/format.test.tscovers repeated{b}/{c}and{a}/{a0}, repeated indexed variables across two series, HTML encoding, unknown variables,formatTplSimple, and a bar series label formatter. The new cases fail without the fix and pass with it. The full unit test suite,npx tsc --noEmitand ESLint on the changed files pass.Merging options
Other information
Based on
release, which already has the replacers from #21751. The helper takes the value as astring, and the inserted text stays literal, so the$tests from #21751 still pass. Onrelease, the full unit test suite (231 tests),npx tsc --noEmitand ESLint on the changed files pass.This change was drafted with Claude Code (claude-opus-5-5); the test results above are from the runs described.