Why Azure appsettings encoding bring me wrong chars?

倖福魔咒の 提交于 2020-06-14 05:57:07

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!