From 4a677a25bad5fdf14b559237c1151454de323d50 Mon Sep 17 00:00:00 2001 From: deathcap Date: Sat, 30 Jan 2016 21:40:03 -0800 Subject: [PATCH] Use endian-toggle for UTF-16BE encoding (not in nodejs, see https://github.com/nodejs/node-v0.x-archive/issues/1684) --- package.json | 1 + src/createServer.js | 8 ++------ 2 files changed, 3 insertions(+), 6 deletions(-) diff --git a/package.json b/package.json index fd3abd5..4fd7100 100644 --- a/package.json +++ b/package.json @@ -29,6 +29,7 @@ "browser": "browser.js", "devDependencies": { "babel-preset-es2015": "^6.3.13", + "endian-toggle": "0.0.0", "espower-loader": "^1.0.0", "gulp": "^3.9.0", "gulp-babel": "^6.1.1", diff --git a/src/createServer.js b/src/createServer.js index 6dd9d88..9a4b71d 100644 --- a/src/createServer.js +++ b/src/createServer.js @@ -5,6 +5,7 @@ var states = require("./states"); var bufferEqual = require('buffer-equal'); var Server = require('./server'); var UUID = require('uuid-1345'); +var endianToggle = require('endian-toggle'); module.exports=createServer; @@ -139,12 +140,7 @@ function createServer(options) { function sendPingResponse(responseString) { function utf16be(s) { - //var responseBuffer = new Buffer(responseString, 'utf16le'); // unfortunately, we need utf16be not le - //var responseBuffer = new Buffer(responseString, 'ucs2'); // aliases for utf16le - // hack semi-UTF16BE encoding, by prefixing each character with a null byte - // TODO: use a real encoder, maybe https://github.com/ForbesLindesay/legacy-encoding? - // uses https://github.com/ashtuchkin/iconv-lite which has 'utf16-be'. use or separate out? - return new Buffer([''].concat(s.split('')).join('\0'), 'binary'); + return endianToggle(new Buffer(s, 'utf16le'), 16); } var responseBuffer = utf16be(responseString);