为什么Azure应用设置编码会给我带来错误的字符? [英] Why Azure appsettings encoding bring me wrong chars?

查看:112
本文介绍了为什么Azure应用设置编码会给我带来错误的字符?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对天青的appsettings编码有疑问.

I have a problem whit the azure appsettings encoding.

我有一个部署到应用程序服务中的node.js应用程序.当使用process.env调用环境变量时,这些值以错误的编码形式出现.我曾期望"utf8"编码支持像ñ",ó",í",á",é",ú"之类的字符,但取而代之的是,我得到像¢",£"的字符","等.

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.

你能帮我吗?

谢谢!

推荐答案

完全一样.

process.env似乎存在一些编码问题,因为在Kudu(https://<webappname>.scm.azurewebsites.net/Env.cshtml#envVariables)上,应用程序设置可能会按预期显示.同样在.net应用程序中,我也能够获取正确的字符串.

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.

将输入与我们得到的解码结果进行比较,我发现它可以使用 CP437 win1252 )进行解码.

Comparing the input with the decoded result we got, I found it may be encoded using CP437 and decoded using another charset like win1252.

因此,一种解决方法是对以某种方式格式错误的字符串进行编码,然后使用其编码的字符集再次对其进行解码.安装 iconv-lite ,然后尝试执行以下代码段.

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');

这篇关于为什么Azure应用设置编码会给我带来错误的字符?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆