Repository navigation
fix(axis, radar, geo): preserve literal replacement characters in string formatters - #21847
farisbasha wants to merge 1 commit into
Conversation
…ing formatters
The string formatters of the category axis label (`{value}`), the radar
indicator name (`{value}`) and the geo region label (`{a}`) passed the
user's text as the replacement string of `String.prototype.replace`.
So `$&`, `$$`, `` $` `` and `$'` inside a category, indicator or region
name were expanded instead of being shown literally.
Use a replacer function, as apache#21751 did for formatTpl and apache#21787 did for
the aria label.
|
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. |
|
Nice fix — using a function as the replacement avoids the |
|
Thanks for looking and for the list! I'd prefer to keep this PR scoped to the axis/radar/geo label formatters, to match the earlier merged fixes (#21751, #21787) and keep it easy to review. If the maintainers want, I'm happy to send the legend / |
Brief Information
This pull request is in the type of:
What does this PR do?
Shows
$&,$$,$`and$'literally in category axis labels, radar indicator names and geo region labels that use a string formatter.Fixed issues
None filed. Same bug class as #21751 (formatTpl) and #21787 (aria label).
Details
Before: What was the problem?
Three string formatters pass the user's text as the replacement string of
String.prototype.replace, so JavaScript expands the special$patterns in it:src/coord/axisHelper.tsmakeLabelFormatter:axisLabel.formattersuch as'Label: {value}'src/coord/radar/RadarModel.ts:radar.axisName.formattersuch as'Name: {value}'src/coord/geo/GeoModel.tsgetFormattedLabel:geo.label.formattersuch as'Geo: {a}'For example, with
axisLabel.formatter: 'Label: {value}!':Item $&Label: Item {value}!Item $$Label: Item $!Item $`Label: Item Label: !Item $'Label: Item !!After: How does it behave after the fixing?
The value is passed through a replacer function (
() => value), the same way #21751 and #21787 fixedformatTpland the aria label, so the text is inserted as is. Nothing else changes.New unit test
test/ut/spec/component/stringFormatter.test.tschecks the three formatters with$&,$$,$`,$'and plain text.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/component/stringFormatter.test.tsMerging options
Other information
I used an AI assistant to find this and write the change. The new test runs in CI; I did not run the test suite locally.