Problem/motivation:
At its current state, `src/Plugin/Field/FieldFormatter/BigIntItemDefaultFormatter.php` returns incorrect values under certain conditions.
The method numberFormat processes the string as follows:
- Obtains three characters, starting from the end of a numeric string
- Stores the obtained characters in the above step in an array
- Removes the obtained characters from the original numeric string in the variable
- Repeats 1~3 until the entire string is processed
- Restores the numeric string from the characters stored in the array, with the specified delimiter
The problem lies in the steps #2 and 3. When the length of the numeric string is either two, or the remainder is 2 when the length is divided by 3, the formatter places the first character and the delimiter at the beginning of the string.
Examples:
- 10 => 110 or 1,10
- 10000 => 110000 or 1,10,000
- 10000000 => 110000000 or 1,10,000,000
Proposed resolution
Apply the patch to correct the formatting issue without making changes to the functionality of the numberFormat method itself.
| Comment | File | Size | Author |
|---|---|---|---|
| #4 | 3159564-4.patch | 836 bytes | dokumori |
| bigint.1.x.numberFormat.patch | 854 bytes | dokumori |
Comments
Comment #2
dokumori commentedFYI: The problem was originally discovered by @kyk and the patch was produced by @JunyaOnishi, both of whom are from ANNAI. Please assign credits to respective contributors.
(I am only a messenger so deserve no credits)
Comment #3
bmustafa commentedNot able to apply patch
Executing command (D:\wamp64\www\workbench\workbench_d9_test1\modules\contrib\bigint): git checkout "3224ab30629bb1ab89b276fba2d6ce2cc6c594b8" -- && git reset --hard "3224ab30629bb1ab89b276fba2d6ce2cc6c594b8" --
- Applying patches for drupal/bigint
Checked CA file C:\Users\User\AppData\Local\Temp\opeA378.tmp: valid
https://www.drupal.org/files/issues/2020-07-16/bigint.1.x.numberFormat.p... (d9_fix_bigint)
Downloading https://www.drupal.org/files/issues/2020-07-16/bigint.1.x.numberFormat.p...
Testing ability to patch with git apply. This command may produce errors that can be safely ignored.
git -C "modules/contrib/bigint" apply --check -v "-p1" "C:\Users\User\AppData\Local\Temp/5f14aacfa68a5.patch"
Executing command (CWD): git -C "modules/contrib/bigint" apply --check -v "-p1" "C:\Users\User\AppData\Local\Temp/5f14aacfa68a5.patch"
error: unrecognized input
Testing ability to patch with git apply. This command may produce errors that can be safely ignored.
git -C "modules/contrib/bigint" apply --check -v "-p0" "C:\Users\User\AppData\Local\Temp/5f14aacfa68a5.patch"
Executing command (CWD): git -C "modules/contrib/bigint" apply --check -v "-p0" "C:\Users\User\AppData\Local\Temp/5f14aacfa68a5.patch"
error: unrecognized input
Testing ability to patch with git apply. This command may produce errors that can be safely ignored.
git -C "modules/contrib/bigint" apply --check -v "-p2" "C:\Users\User\AppData\Local\Temp/5f14aacfa68a5.patch"
Executing command (CWD): git -C "modules/contrib/bigint" apply --check -v "-p2" "C:\Users\User\AppData\Local\Temp/5f14aacfa68a5.patch"
error: unrecognized input
Testing ability to patch with git apply. This command may produce errors that can be safely ignored.
git -C "modules/contrib/bigint" apply --check -v "-p4" "C:\Users\User\AppData\Local\Temp/5f14aacfa68a5.patch"
Executing command (CWD): git -C "modules/contrib/bigint" apply --check -v "-p4" "C:\Users\User\AppData\Local\Temp/5f14aacfa68a5.patch"
error: unrecognized input
patch "-p1" --no-backup-if-mismatch -d "modules/contrib/bigint" < "C:\Users\User\AppData\Local\Temp/5f14aacfa68a5.patch"
Executing command (CWD): patch "-p1" --no-backup-if-mismatch -d "modules/contrib/bigint" < "C:\Users\User\AppData\Local\Temp/5f14aacfa68a5.patch"
patch: **** Only garbage was found in the patch input.
patch "-p0" --no-backup-if-mismatch -d "modules/contrib/bigint" < "C:\Users\User\AppData\Local\Temp/5f14aacfa68a5.patch"
Executing command (CWD): patch "-p0" --no-backup-if-mismatch -d "modules/contrib/bigint" < "C:\Users\User\AppData\Local\Temp/5f14aacfa68a5.patch"
patch: **** Only garbage was found in the patch input.
patch "-p2" --no-backup-if-mismatch -d "modules/contrib/bigint" < "C:\Users\User\AppData\Local\Temp/5f14aacfa68a5.patch"
Executing command (CWD): patch "-p2" --no-backup-if-mismatch -d "modules/contrib/bigint" < "C:\Users\User\AppData\Local\Temp/5f14aacfa68a5.patch"
patch: **** Only garbage was found in the patch input.
patch "-p4" --no-backup-if-mismatch -d "modules/contrib/bigint" < "C:\Users\User\AppData\Local\Temp/5f14aacfa68a5.patch"
Executing command (CWD): patch "-p4" --no-backup-if-mismatch -d "modules/contrib/bigint" < "C:\Users\User\AppData\Local\Temp/5f14aacfa68a5.patch"
patch: **** Only garbage was found in the patch input.
Could not apply patch! Skipping. The error was: Cannot apply patch https://www.drupal.org/files/issues/2020-07-16/bigint.1.x.numberFormat.p...
Comment #4
dokumori commentedApologies - here's the correct patch. I can confirm this applies to bigint 8.x-1.x
Comment #5
bmustafa commentedYes that patch is proper now.
earlier i have manually applied the patch by hand-editing the file and removing the earlier code lines.
Anyhow, the issue is corrected per this patch as i see in the website, the integers look proper now.
Comment #6
dokumori commentedThank you @bmustafa for testing the patch. I'm changing the status to RTBC
Comment #8
recrit commented