Skip to content

Commit c697eaa

Browse files
chatman-mediabeaugunderson
authored andcommitted
fix: Address6.fromURL squelches port 65536 as valid
Valid ports are 0-65535 (16-bit), but the range check used `> 65536`, so a port of exactly 65536 slipped through instead of being nulled out like every other out-of-range value. Looks like a plain off-by-one that's been there since the very first commit. Updated the two existing tests that had baked the wrong expectation in and added one pinning 65535 as the actual max.
1 parent d46eb43 commit c697eaa

2 files changed

Lines changed: 13 additions & 6 deletions

File tree

‎src/ipv6.ts‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -246,8 +246,8 @@ export class Address6 {
246246
if (port) {
247247
port = parseInt(port, 10);
248248

249-
// squelch out of range ports
250-
if (port < 0 || port > 65536) {
249+
// squelch out of range ports (valid ports are 0-65535)
250+
if (port < 0 || port > 65535) {
251251
port = null;
252252
}
253253
} else {

‎test/functionality-v6-test.ts‎

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -608,11 +608,18 @@ describe('v6', () => {
608608
expect(obj.port).to.equal(80);
609609
});
610610

611-
it('should work with a URL with a long port number', () => {
611+
it('should work with the highest valid port number', () => {
612+
const obj = Address6.fromURL('http://[2001:db8::5]:65535/foo');
613+
614+
expect(obj.address?.address).to.equal('2001:db8::5');
615+
expect(obj.port).to.equal(65535);
616+
});
617+
618+
it('should parse the address but fail with a port number one past the valid range', () => {
612619
const obj = Address6.fromURL('http://[2001:db8::5]:65536/foo');
613620

614621
expect(obj.address?.address).to.equal('2001:db8::5');
615-
expect(obj.port).to.equal(65536);
622+
expect(obj.port).to.equal(null);
616623
});
617624

618625
it('should work with a address with a port', () => {
@@ -622,11 +629,11 @@ describe('v6', () => {
622629
expect(obj.port).to.equal(80);
623630
});
624631

625-
it('should work with an address with a long port', () => {
632+
it('should parse the address but fail with an out of range port', () => {
626633
const obj = Address6.fromURL('[2001:db8::5]:65536');
627634

628635
expect(obj.address?.address).to.equal('2001:db8::5');
629-
expect(obj.port).to.equal(65536);
636+
expect(obj.port).to.equal(null);
630637
});
631638

632639
it('should parse the address but fail with an invalid port', () => {

0 commit comments

Comments
 (0)