Skip to content
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

console.table appears to have padding issues when ¥ (FULLWIDTH YEN SIGN) is involved #29299

Closed
runjak opened this issue Aug 24, 2019 · 2 comments
Labels
console Issues and PRs related to the console subsystem.

Comments

@runjak
Copy link

runjak commented Aug 24, 2019

  • Version: v10.16.2 (using nvm I can reproduce with v12.9.0 too)
  • Platform: Linux stormo 5.2.9-arch1-1-ARCH #1 SMP PREEMPT Fri Aug 16 11:29:43 UTC 2019 x86_64 GNU/Linux
  • Subsystem: console

I've been comparing differences between currency formattings for different locales, when I stumbled across a minor irregularity in the output of console.table.

Consider the following example code:

const items = [
  {foo: '2', bar: '3'},
  {foo: '¥2', bar: '3'},
  {foo: '2', bar: 'abcdefghijklmnopqrstuvwxyz'},
  {foo: '-¥12,345,678.90', bar: '¥-12,345,678.90'},
  {foo: '¥2', bar: '¥3'},
  {foo: '2', bar: '3'},
];

console.table(items);

The resulting console output on my machine appears like this:
Screenshot_2019-08-25_00-22-22

From what I can gather so far:

  • It seems that simply having in a string is sufficient to provoke the behavior given that it is the FULLWIDTH YEN SIGN (U+FFE5) and not the YEN SIGN (U+00A5).
  • The behavior seems to be independent of table length - >400 items as well as a single item had the formatting oddity.
  • It seems that having a longer string like abc…xyz in a different row doesn't change the outcome.

To me this hints that the length for the specific strings with in it could be calculated to be shorter than it actually is.

For completeness here's a screenshot of the original output I encountered:
Screenshot_2019-08-25_00-02-29


After realizing that there are also rather short entries in my original output, I've created this additional test case:

const items = [
  {foo: '¥', bar: '¥'},
];

console.table(items);

const [{ foo, bar }] = items;

console.log({foo});
console.table(Array.from(foo + bar).map((s) => ({s, charCode: s.charCodeAt(0), length: s.length})));

The corresponding output looks like this:
Screenshot_2019-08-25_00-44-27

It appears that the problem here lies with charCode 65509 rather than with 165.
So I'm concerned about the FULLWIDTH YEN SIGN at code point U+FFE5 rather than the YEN SIGN at code point U+00A5.


I've had a look at #27915 before and am under the impression that this is the right channel for this kind of issue. Please feel free to educate me otherwise ;)

@devsnek
Copy link
Member

devsnek commented Aug 24, 2019

cc @srl295 is there any way to fix this besides a specific override for this character?

@devsnek devsnek added the console Issues and PRs related to the console subsystem. label Aug 24, 2019
addaleax added a commit to addaleax/node that referenced this issue Aug 24, 2019
This is more accurate for displayed full-width characters
(e.g. CJK ones) and makes the calculations match the ones we
use in the readline module.

Fixes: nodejs#29299
@addaleax
Copy link
Member

#29300 should work for this, it’s the solution we use for readline/the REPL.

BridgeAR pushed a commit that referenced this issue Sep 3, 2019
This is more accurate for displayed full-width characters
(e.g. CJK ones) and makes the calculations match the ones we
use in the readline module.

Fixes: #29299

PR-URL: #29300
Reviewed-By: Gus Caplan <me@gus.host>
Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com>
Reviewed-By: Yongsheng Zhang <zyszys98@gmail.com>
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Tobias Nießen <tniessen@tnie.de>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
BridgeAR pushed a commit that referenced this issue Sep 4, 2019
This is more accurate for displayed full-width characters
(e.g. CJK ones) and makes the calculations match the ones we
use in the readline module.

Fixes: #29299

PR-URL: #29300
Reviewed-By: Gus Caplan <me@gus.host>
Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com>
Reviewed-By: Yongsheng Zhang <zyszys98@gmail.com>
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Tobias Nießen <tniessen@tnie.de>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
console Issues and PRs related to the console subsystem.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants