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

Encoding Issue with Special Characters in Node.js 22 Docker Image #2138

Closed
newtonaugusto opened this issue Sep 3, 2024 · 4 comments
Closed

Comments

@newtonaugusto
Copy link

Environment

  • Platform: Linux (inside Docker container), AWS Cloud (ECS, EC2) and localhost
  • Docker Version: any
  • Node.js Version: node:22
  • Image Tag: node:22-alpine, node:22-bullseye

Expected Behavior

Special characters should be correctly encoded and displayed as "Teste: coração" in all instances.
image

image

Current Behavior

When handling special characters like "ç" in strings, the characters are sometimes improperly encoded or displayed as garbled text.

image

image

Possible Solution

Downgrade Node.js Version: As a temporary fix, you can switch to Node.js 18 or 21 Docker images where the encoding issue does not occur.
Investigate Locale Settings: Although I tried setting locale environment variables, further investigation into locale handling within the Node.js 22 Docker images might reveal a more permanent solution.
Rebuild Docker Image: Consider rebuilding the Docker image with a different base OS that handles locales differently, or try explicitly setting the encoding in your Node.js application to ensure consistent behavior.

Steps to Reproduce

  1. Clone the following repository:
    GitHub Repository
  2. Build and run the application using the Node.js 22 Docker image:
    Alternatively, you can pull the pre-built Docker image: itacirgabral/node22alpinetestencode:0.0.1
  3. Access the endpoint /status-encoding and observe the returned string containing special characters such as "Teste: coração".
  4. Use the wrk tool to perform a load test on the application to increase the chances of encountering the encoding issue:
  1. Observe the output, especially when using Buffer.from('Teste: coração').toString('utf8').

Additional Information

I tested the same application with Node.js 18 and 21 Docker images and did not encounter the issue. It seems specific to the Node.js 22 images.
Locale settings attempted: pt_BR.UTF-8, LC_ALL=pt_BR.UTF-8, LANG=pt_BR.UTF-8

I tried setting various locale environment variables (e.g., LANG, LC_ALL, LC_CTYPE), but the issue persisted. This suggests the problem might be related to the Node.js 22 Docker image itself.

@LaurentGoderre
Copy link
Member

Are you sure the issue isn't with your dev tools not handling utf8 as default?

@meyfa
Copy link

meyfa commented Sep 3, 2024

Could be related to nodejs/node#54543

@newtonaugusto
Copy link
Author

I'm sure. I ran the same code, with the same environment with both images, one breaks and the other doesn't.

I noticed this issue when I pushed a code change to production that included a single line that added a phone number to messageBird. It shouldn't break, it was the same infrastructure.

@nschonni
Copy link
Member

nschonni commented Sep 4, 2024

#2135 (comment)
22.8 didn't land upstream till after you opened this, and it may resolve the issue, by as like the other issue, this is an upstream issue that nothing in this repo can fix

@nschonni nschonni closed this as not planned Won't fix, can't repro, duplicate, stale Sep 4, 2024
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

4 participants