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

Date.toLocaleString contains invalid delimiter character #45753

Closed
stsoib opened this issue Dec 5, 2022 · 6 comments
Closed

Date.toLocaleString contains invalid delimiter character #45753

stsoib opened this issue Dec 5, 2022 · 6 comments

Comments

@stsoib
Copy link

stsoib commented Dec 5, 2022

Version

v18.12.1+1-b20221130T14204672

Platform

Linux osrvdv-rr-441 3.10.0-957.35.2.el7.x86_64 #1 SMP Wed Sep 18 05:51:28 EDT 2019 x86_64 x86_64 x86_64 GNU/Linux

Subsystem

No response

What steps will reproduce the bug?

Run this script:

#!/usr/bin/env node

const os = require('os')

console.log('Operating System\n', os.platform(), os.release())
console.log('Node JS Version\n', process.version)

const str = new Date().toLocaleString({ locale: 'en-US' })
console.log(`String value of', 'new Date().toLocaleString({ locale: 'en-US' })\n`, `"${str}"`)
console.log('Char value at position 18\n', `"${str.charAt(18)}"`)
console.log('Char code at position 18\n', str.charCodeAt(18))

On Linux I see:

CaptureA

On Windows I see:

CaptureB

How often does it reproduce? Is there a required condition?

No response

What is the expected behavior?

Delimiter of en-US should just be regular whitespace, and this should be consistent across operating systems.

What do you see instead?

CaptureC

Additional information

No response

@richardlau
Copy link
Member

richardlau commented Dec 5, 2022

What does node -p process.versions (note the s at the end) print? This is the behaviour you would see with ICU 72.1 (see the same report for Node.js 19: #45171) but our binaries of Node.js 18.12.1 contain ICU 71.1.

@stsoib
Copy link
Author

stsoib commented Dec 5, 2022

What does node -p process.versions (note the s at the end) print? This is the behaviour you would see with ICU 72.1 (see the same report for Node.js 19: #45171) but our binaries of Node.js 18.12.1 contain ICU 71.1.

{
  node: '18.12.1',
  v8: '10.2.154.15-node.12',
  uv: '1.44.2',
  zlib: '1.2.13',
  brotli: '1.0.9',
  ares: '1.18.1',
  modules: '108',
  nghttp2: '1.47.0',
  napi: '8',
  llhttp: '6.0.10',
  openssl: '3.0.7+quic',
  cldr: '42.0',
  icu: '72.1',
  tz: '2022f',
  unicode: '15.0',
  ngtcp2: '0.8.1',
  nghttp3: '0.7.0'
}

@stsoib
Copy link
Author

stsoib commented Dec 5, 2022

What does it mean if it prints node: '18.12.1' AND icu: '72.1'?

@richardlau
Copy link
Member

It means whoever compiled your binaries (not us) has either replaced ICU with a newer one or linked to your system ICU.

@stsoib
Copy link
Author

stsoib commented Dec 5, 2022

I see. Let me check with my colleague to confirm this. Thanks for clarifying!

@Pacheco95
Copy link

Pacheco95 commented Nov 6, 2023

I had a similar problem today. The Intl API is returning a string with the "No-Break Space" character (code 160) instead of the ASCII space character (code 32)

Steps to reproduce:

const expected = "R$ 100.000,00"

let formatted = (100_000).toLocaleString("pt-BR", { style: "currency", currency: "BRL" })

console.log(formatted === expected, expected.indexOf(" "), formatted.indexOf(" "));

formatted = new Intl.NumberFormat("pt-BR", { style: "currency", currency: "BRL" }).format(100_000);

console.log(formatted === expected, expected.indexOf(" "), formatted.indexOf(" "));

console.log(formatted.charCodeAt(2), expected.charCodeAt(2))

Output:

false 2 -1
false 2 -1
160 32

System info

➜ node -p process.versions
{
  node: '18.17.0',
  acorn: '8.8.2',
  ada: '2.5.0',
  ares: '1.19.1',
  brotli: '1.0.9',
  cldr: '43.0',
  icu: '73.1',
  llhttp: '6.0.11',
  modules: '108',
  napi: '9',
  nghttp2: '1.52.0',
  nghttp3: '0.7.0',
  ngtcp2: '0.8.1',
  openssl: '3.0.9+quic',
  simdutf: '3.2.12',
  tz: '2023c',
  undici: '5.22.1',
  unicode: '15.0',
  uv: '1.44.2',
  uvwasi: '0.0.18',
  v8: '10.2.154.26-node.26',
  zlib: '1.2.13.1-motley'
}                                                                                                                                                                                                                                   

➜ cat /etc/os-release                                    
PRETTY_NAME="Ubuntu 22.04.3 LTS"
NAME="Ubuntu"
VERSION_ID="22.04"
VERSION="22.04.3 LTS (Jammy Jellyfish)"
VERSION_CODENAME=jammy
ID=ubuntu
ID_LIKE=debian
HOME_URL="https://www.ubuntu.com/"
SUPPORT_URL="https://help.ubuntu.com/"
BUG_REPORT_URL="https://bugs.launchpad.net/ubuntu/"
PRIVACY_POLICY_URL="https://www.ubuntu.com/legal/terms-and-policies/privacy-policy"
UBUNTU_CODENAME=jammy

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants