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:

  1. Obtains three characters, starting from the end of a numeric string
  2. Stores the obtained characters in the above step in an array
  3. Removes the obtained characters from the original numeric string in the variable
  4. Repeats 1~3 until the entire string is processed
  5. 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.

CommentFileSizeAuthor
#4 3159564-4.patch836 bytesdokumori
bigint.1.x.numberFormat.patch854 bytesdokumori

Comments

dokumori created an issue. See original summary.

dokumori’s picture

FYI: 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)

bmustafa’s picture

Status: Active » Needs work

Not 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...

dokumori’s picture

Status: Needs work » Needs review
StatusFileSize
new836 bytes

Apologies - here's the correct patch. I can confirm this applies to bigint 8.x-1.x

bmustafa’s picture

Yes 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.

dokumori’s picture

Status: Needs review » Reviewed & tested by the community

Thank you @bmustafa for testing the patch. I'm changing the status to RTBC

  • alansaviolobo committed 5a46caf on 8.x-1.x
    Issue #3159564 by kyk,JunyaOnishi: Numbers and delimiters added to a...
recrit’s picture

Version: 8.x-1.0 » 8.x-1.x-dev
Status: Reviewed & tested by the community » Fixed

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.