Internationalization and localization tools


Locale-Sensitive JavaScript NodeJS Method

Buffer.alloc(size[, fill[, encoding]]);

Internationalization (I18n) Method Overview

The Buffer.alloc method allocates a new buffer of size bytes. If fill is undefined, then the Buffer will be zero-filled.


For example:

const buf = Buffer.alloc(5);
console.log(buf);
// <Buffer 00 00 00 00 00>

Click here for additional details.

I18n Issues

Whether or not calling Buffer.alloc is an i18n issue is dependent on how it is being used in the application. These issues resolve around the buffer containing strings. Some possible issues are:

  • The encoding may need to be specified, or may be incorrect.
  • The specified buffer size may be based upon the number of string characters passed. Some unicode characters require more bytes to encode than others. If some of the characters passed require more bytes to encode, then the size will be incorrect.

Suggested Replacement

Make sure that you pass in the correct encoding for your application usage. If calculating the size of the buffer from a string, do not assume that the buffer size will be directly proportional to the number of string characters.

Globalyzer will detect this method and report it as an i18n issue. If you have determined that the call is being handled correctly, you can use Globalyzer's Ignore Comment functionality to ensure that it isn't picked up in a subsequent scan.



Locale-Sensitive JavaScript Methods

 

Lingoport internationalization and localization services and software