forked from WebKit/WebKit
-
Notifications
You must be signed in to change notification settings - Fork 52
ICU: backport ICU-23110 (percent formatRange scaled twice on approximately path) #374
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
robobun
wants to merge
2
commits into
main
Choose a base branch
from
farm/7cfed714/icu-23110-numrange-percent
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,56 @@ | ||
| Backport of ICU-23110 (https://unicode-org.atlassian.net/browse/ICU-23110, | ||
| upstream commit 757be359). NumberRangeFormatterImpl::formatApproximately | ||
| re-ran preProcess on data.quantity1 after the caller had already preProcessed | ||
| it, so any multiplier (scale/100 for style:"percent") was applied twice on | ||
| the identity/approximately path. Fixed upstream in ICU 78.1; drop this patch | ||
| once the bundled ICU is >= 78. | ||
|
|
||
| --- a/source/i18n/numrange_impl.cpp | ||
| +++ b/source/i18n/numrange_impl.cpp | ||
| @@ -160,6 +160,8 @@ void NumberRangeFormatterImpl::format(UFormattedNumberRangeData& data, bool equa | ||
| return; | ||
| } | ||
|
|
||
| + DecimalQuantity quantityBackup(data.quantity1); | ||
| + | ||
| MicroProps micros1; | ||
| MicroProps micros2; | ||
| formatterImpl1.preProcess(data.quantity1, micros1, status); | ||
| @@ -216,7 +218,7 @@ void NumberRangeFormatterImpl::format(UFormattedNumberRangeData& data, bool equa | ||
| UNUM_IDENTITY_RESULT_EQUAL_BEFORE_ROUNDING): | ||
| case identity2d(UNUM_IDENTITY_FALLBACK_APPROXIMATELY_OR_SINGLE_VALUE, | ||
| UNUM_IDENTITY_RESULT_EQUAL_AFTER_ROUNDING): | ||
| - formatApproximately(data, micros1, micros2, status); | ||
| + formatApproximately(data, quantityBackup, micros1, micros2, status); | ||
| break; | ||
|
|
||
| case identity2d(UNUM_IDENTITY_FALLBACK_APPROXIMATELY_OR_SINGLE_VALUE, | ||
| @@ -248,15 +250,15 @@ void NumberRangeFormatterImpl::formatSingleValue(UFormattedNumberRangeData& data | ||
|
|
||
|
|
||
| void NumberRangeFormatterImpl::formatApproximately (UFormattedNumberRangeData& data, | ||
| + DecimalQuantity quantity, | ||
| MicroProps& micros1, MicroProps& micros2, | ||
| UErrorCode& status) const { | ||
| if (U_FAILURE(status)) { return; } | ||
| if (fSameFormatters) { | ||
| // Re-format using the approximately formatter: | ||
| MicroProps microsAppx; | ||
| - data.quantity1.resetExponent(); | ||
| - fApproximatelyFormatter.preProcess(data.quantity1, microsAppx, status); | ||
| - int32_t length = NumberFormatterImpl::writeNumber(microsAppx.simple, data.quantity1, data.getStringRef(), 0, status); | ||
| + fApproximatelyFormatter.preProcess(quantity, microsAppx, status); | ||
| + int32_t length = NumberFormatterImpl::writeNumber(microsAppx.simple, quantity, data.getStringRef(), 0, status); | ||
| length += microsAppx.modInner->apply(data.getStringRef(), 0, length, status); | ||
| length += microsAppx.modMiddle->apply(data.getStringRef(), 0, length, status); | ||
| microsAppx.modOuter->apply(data.getStringRef(), 0, length, status); | ||
| --- a/source/i18n/numrange_impl.h | ||
| +++ b/source/i18n/numrange_impl.h | ||
| @@ -64,6 +64,7 @@ class NumberRangeFormatterImpl : public UMemory { | ||
| UErrorCode& status) const; | ||
|
|
||
| void formatApproximately(UFormattedNumberRangeData& data, | ||
| + DecimalQuantity quantity, | ||
| MicroProps& micros1, MicroProps& micros2, | ||
| UErrorCode& status) const; | ||
|
|
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🟡 Note that the native Windows build path (
windows-release.ps1→build-icu.ps1) — still used by CI for thebun-webkit-windows-arm64-debugartifact — downloadsicu4c-73_2-src.tgzand builds via MSBuild without applying any.patchto the ICU C++ source, so that artifact will still showformatRange(0.5, 0.5) → "~5,000%". This is a pre-existing gap (udata-decompress-hook.patchis also skipped there) and only affects a debug-only artifact, so probably fine as a follow-up rather than blocking this PR.Extended reasoning...
What this is
The PR applies
icu/icu-23110-numrange-percent.patchin every Dockerfile that builds ICU from source —Dockerfile,Dockerfile.musl,Dockerfile.android,Dockerfile.freebsd, andDockerfile.windows— exactly as the description says. However, there is one more ICU-from-source build path in the repo that CI still exercises: the native Windows runner job, which goeswindows-release.ps1→build-icu.ps1. That path is not touched by this PR, so the artifact it produces will still contain unpatched ICU 73.2 with the double-scaling bug.Code path
In
.github/workflows/build-reusable.yml:Dockerfile.windows, but the nativewindowsjob is kept for arm64-debug, andwindows-release.ps1"remains for building on a real Windows machine".windowsjob matrix has a single entry —runner: windows-11-arm,build-type: Debug,label: bun-webkit-windows-arm64-debug../windows-release.ps1 -Platform ARM64.bun-webkit-windows-arm64-debugartifact is downloaded and published to theautobuild-{sha}release alongside all the Docker-built artifacts.In
build-icu.ps1:icu4c-73_2-src.tgzfrom the upstream release..vcxproj/.props/makedata.makbuild-config files. No.patchfromicu/is ever applied tosource/i18n/numrange_impl.cppornumrange_impl.h.So
sicuin.libinbun-webkit-windows-arm64-debugis compiled from unmodified ICU 73.2numrange_impl.cpp.Why nothing existing prevents it
Dockerfile.windows(lines 209–210) does apply the patch, but that file only produces the cross-compiledx64/arm64release/LTO/asan artifacts. The nativewindowsjob doesn't use Docker at all — it invokesbuild-icu.ps1directly on the runner, and that script has never had a step that readsicu/*.patch.Step-by-step proof
windowsjob onwindows-11-arm→./windows-release.ps1 -Platform ARM64.windows-release.ps1callsbuild-icu.ps1, which fetchesicu4c-73_2-src.tgzand extracts it.build-icu.ps1edits vcxproj/props for/MTstatic, then runs MSBuild.source/i18n/numrange_impl.cppis untouched, so it still containsdata.quantity1.resetExponent(); fApproximatelyFormatter.preProcess(data.quantity1, ...)on the approximately path.sicuin.libis packed intobun-webkit-windows-arm64-debug.tar.gzand published.new Intl.NumberFormat("en", {style:"percent"}).formatRange(0.5, 0.5): JSC callsunumrf_formatDoubleRange(0.5, 0.5), ICU'sformatterImpl1.preProcessscales 0.5 → 50, the identity check picksUNUM_IDENTITY_FALLBACK_APPROXIMATELY,formatApproximatelycallsfApproximatelyFormatter.preProcesson the same already-scaled quantity → 5000, and the output is"~5,000%"instead of"~50%".Impact
Low. Only the
bun-webkit-windows-arm64-debugartifact is affected — a Debug build, not something end users install. All release/LTO Windows artifacts come fromDockerfile.windowsand are correctly patched. Also, this is a pre-existing infrastructure gap:build-icu.ps1already skipsudata-decompress-hook.patch, so "ICU source patches are not applied on the native Windows path" predates this PR rather than being introduced by it. The PR description scoped itself to "every Dockerfile that builds ICU from source", and it delivers exactly that.Fix
As a follow-up (not blocking): have
build-icu.ps1applyicu/*.patchafter extraction — e.g.git apply(git is on the runner), orpatch.exefrom Git for Windows, or a targeted PowerShell-replaceonnumrange_impl.cpp/.h. Alternatively, note the limitation in the PR / patch header so the arm64-debug divergence is documented.