Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why Azure appsettings encoding bring me wrong chars?

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!

like image 462
Alvaro Jose Julio Beltran Avatar asked Nov 18 '18 17:11

Alvaro Jose Julio Beltran


People also ask

Why is Azure Data Warehouse encoding a UTF-8 file wrong?

This same document was uploaded in the past to BLOB storage and imported in the same fashion into Azure Data Warehouse without errors via Polybase. The value that causes the UTF-8 encoding error is a URL mangled among 1 million other records. It looks like there are ASCII characters coming in even though it's a UTF-8 document.

What are app settings in Azure Functions?

App settings reference for Azure Functions. App settings in a function app contain global configuration options that affect all functions for that function app. When you run locally, these settings are accessed as local environment variables. This article lists the app settings that are available in function apps.

What is the purpose of the Azure App service environment variable?

This environment variable is populated automatically by the Azure App Service platform and is used to configure the integrated authentication module. The value of this environment variable corresponds to the V2 (non-classic) authentication configuration for the current app in Azure Resource Manager. It's not intended to be configured explicitly.

How to ignore encoding error in Azure Data Lake Analytics?

Azure Data Lake Analytics does not allow you to ignore the error as it's an encoding issue. I'd be happy invalidating the record all together like you can in Azure Data Warehouse. importazureencodingunicodehadoop


1 Answers

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');
like image 133
Jerry Liu Avatar answered Oct 30 '22 10:10

Jerry Liu