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

Incorrect encoding when using DEBUG(node.js inside vscode), it will affect extensions result. #26502

Closed
TonySFU opened this issue May 12, 2017 · 1 comment
Assignees
Labels
*as-designed Described behavior is as designed debug Debug viewlet, configurations, breakpoints, adapter issues

Comments

@TonySFU
Copy link

TonySFU commented May 12, 2017

  • VSCode Version: 1.12.1
  • OS Version: macOS 10.12.4

Steps to Reproduce:

1.Use system node.js will get the correct result.
screen shot 2017-05-11 at 7 27 10 pm

2.Set up a DEBUG(launch.json) and run the same code, will return the incorrect encoding result.
screen shot 2017-05-11 at 7 27 46 pm

This problem only happens on macOS platform, it works correct on Windows 10.

I found this issue few months ago, still can not fix.
https://github.com/goessner/mdmath/issues/13

@weinand weinand added debug Debug viewlet, configurations, breakpoints, adapter issues bug Issue identified by VS Code Team member as probable bug labels May 12, 2017
@weinand
Copy link
Contributor

weinand commented May 12, 2017

'clipboardy' uses the macOS command line tools "pbcopy" and "pbpaste" to access the clipboard. From their online documentation I see that they rely on an environment variable for dealing with encodings.

From "man pbcopy":

pbcopy and pbpaste use locale environment variables to determine the encoding to be used for input and output. For example, absent other locale settings, setting the environment variable LANG=en_US.UTF-8 will cause pbcopy and pbpaste to use UTF-8 for input and output. If an encoding cannot be determined from the locale, the standard C encoding will be used. Use of UTF-8 is recommended. Note that by default the Terminal application uses the UTF-8 encoding and automatically sets the appropriate locale environment variable.

I've experimented a bit with this and found that pbcopy relies on the environment variable "LC_CTYPE". If this variable is undefined pbcopy defaults to the "C" locale (which results in the broken text strings from above).

If VS Code (or any other application) is launched by double clicking or from the Dock, "LC_CTYPE" is undefined. If VS Code (or any other application) is launched from the command line, it inherits "LC_CTYPE" from the terminal (which always seems to have it defined).

Since VS Code is not a terminal, I don't think that we have a good reason to initialise "LC_CTYPE" automatically just so that 'clipboardy' works.

If you use "clipboardy", you'll have to make sure that it always gets the environment it needs. Don't rely on VS Code to establish that environment for you. If your code is launched from another tool (e.g. a macOS application launched from the Dock), you will be in the same situation again that "LC_CTYPE" might be undefined.

I suggest that you make sure in your code that "LC_CTYPE" is never undefined before using "clipboardy".

Something like the following fixed the problem for me:

process.env["LC_CTYPE"] = process.env.LC_CTYPE || "UTF-8";

@weinand weinand closed this as completed May 12, 2017
@weinand weinand added *as-designed Described behavior is as designed and removed bug Issue identified by VS Code Team member as probable bug labels May 12, 2017
@vscodebot vscodebot bot locked and limited conversation to collaborators Nov 18, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
*as-designed Described behavior is as designed debug Debug viewlet, configurations, breakpoints, adapter issues
Projects
None yet
Development

No branches or pull requests

2 participants