js-beautify icon indicating copy to clipboard operation
js-beautify copied to clipboard

TextIOWrapper in __init__ is not constructed with UTF-8 encoding on Windows

Open Mrcubix opened this issue 4 months ago • 0 comments

Description

Currently using this tool to beautify js files downloaded from specified websites. Some script, may contain Unicode character (Chinese comments in my case), which aren't parsed properly. This tool does not seem to open either a specified file, or stdin with UTF-8 when necessary, leading to charmap errors.

write_beautified_output & process_files are both affected by the issue.

However, and this is out of scope of the issue, if the input is opened with the UTF-8 encoding, then at column 65096, a string for some reason is newlined, spaces are inserted in ids & classes, breaking a large portion of the beautifying process.

Input

The code looked like this before beautification:

see https://drunkdeer-antler.com/js/app.d3cb498c.js

Expected Output

The code should have looked like this after beautification:

see https://gist.github.com/Mrcubix/354ca746a0053a6dc1653b8b3b34583b

Actual Output

if opened with UTF-8

see https://gist.github.com/Mrcubix/741b9568f84f9c3cbf3f699a1dff0119

Steps to Reproduce

  1. Install js-beatify via pip
  2. Do the following:
more ./app.d3cb498c.js | js-beautify -o app.d3cb498c.beautified.js

Environment

OS: Windows Python: 3.10.4

Settings

Default

Mrcubix avatar Oct 15 '24 21:10 Mrcubix