Skip to content

Commit 8801bec

Browse files
author
Spencer
committed
[connectors/http] prevent errors caused by multi-byte characters in paths (#756)
* [connectors/http] catch errors caused by multi-byte paths * Check url validity before to run the request * Updated test (cherry picked from commit 0d07233)
1 parent 5d61747 commit 8801bec

File tree

2 files changed

+17
-0
lines changed

2 files changed

+17
-0
lines changed

src/lib/connectors/http.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ var qs = require('querystring');
1919
var AgentKeepAlive = require('agentkeepalive');
2020
var ConnectionAbstract = require('../connection');
2121
var zlib = require('zlib');
22+
var INVALID_PATH_REGEX = /[^\u0021-\u00ff]/
2223

2324
/**
2425
* Connector used to talk to an elasticsearch node via HTTP
@@ -166,6 +167,11 @@ HttpConnector.prototype.request = function (params, cb) {
166167
}
167168
}, this);
168169

170+
if (INVALID_PATH_REGEX.test(reqParams.path) === true) {
171+
cb(new TypeError('ERR_UNESCAPED_CHARACTERS: ' + reqParams.path))
172+
return function () {}
173+
}
174+
169175
request = this.hand.request(reqParams, function (_incoming) {
170176
incoming = _incoming;
171177
status = incoming.statusCode;

test/unit/specs/http_connector.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -230,6 +230,17 @@ describe('Http Connector', function () {
230230
done();
231231
});
232232
});
233+
234+
it('calls back with error when http.request throws an error', function (done) {
235+
var con = new HttpConnection(new Host('http://google.com/thisisinvalid\uffe2'));
236+
237+
stub(con.log, 'error');
238+
239+
con.request({}, function (err) {
240+
expect(err.message).to.eql('ERR_UNESCAPED_CHARACTERS: /thisisinvalid\uffe2');
241+
done();
242+
});
243+
});
233244
});
234245

235246
describe('#request with incomming message error', function () {

0 commit comments

Comments
 (0)