问题
I have a problem whit the azure appsettings encoding.
I have a node.js application deployed into an app service. When calling the environment variables using process.env, the values are comming in wrong encoding. I was expect a "utf8" encoding that supports chars like "ñ", "ó", "í", "á", "é", "ú" but instead of that, I get chars like "¢", "£", " ", etc.
Could you help me?
Thanks!
回答1:
Exactly same thing on my side.
There seems some encoding problem with process.env
as on Kudu(https://<webappname>.scm.azurewebsites.net/Env.cshtml#envVariables
) the app setting could show as expected. Also in a .net app I was able to get the correct string.
Comparing the input with the decoded result we got, I found it may be encoded using CP437 and decoded using another charset like win1252.
So one workaround is to encode the string which have been somehow formatted incorrectly, and decode it again with the charset it's encoded. Install iconv-lite and try following code snippet.
var iconv = require('iconv-lite');
var buf = iconv.encode(process.env.MYTEST, 'win1252');
var result = iconv.decode(buf, 'ibm437');
来源:https://stackoverflow.com/questions/53363462/why-azure-appsettings-encoding-bring-me-wrong-chars