Skip to content

Commit

Permalink
fix: ipv6 addresses parsing
Browse files Browse the repository at this point in the history
  • Loading branch information
perrin4869 committed May 13, 2024
1 parent 3317168 commit ec50f5a
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/node/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -749,7 +749,7 @@ Request.prototype.request = function () {
options.method = this.method;
options.port = url.port;
options.path = path;
options.host = url.hostname;
options.host = utils.normalizeHostname(url.hostname); // ex: [::1] -> ::1
options.ca = this._ca;
options.key = this._key;
options.pfx = this._pfx;
Expand Down
5 changes: 5 additions & 0 deletions src/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,11 @@ exports.cleanHeader = (header, changesOrigin) => {
return header;
};

exports.normalizeHostname = (hostname) => {
const [,normalized] = hostname.match(/^\[([^\]]+)\]$/) || [];
return normalized || hostname;
};

/**
* Check if `obj` is an object.
*
Expand Down
9 changes: 9 additions & 0 deletions test/node/basic.js
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,15 @@ describe('[node] request', () => {
});
});

describe('ipv6 address', () => {
it('should successfully query an ipv6 address', (done) => {
request.get(`http://[::]/url?a=(b%29`).end((error, res) => {
assert.equal('/url?a=(b%29', res.text);
done();
});
});
});

describe('.buffer()', () => {
it('should enable buffering', (done) => {
request
Expand Down

0 comments on commit ec50f5a

Please sign in to comment.