Skip to content

Commit 88d40b3

Browse files
committed
fix: allow literal (RFC2732) IPv6 addresses in TCP URI
1 parent 1a640d1 commit 88d40b3

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

src/adapter/utils.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,20 @@
11
import {existsSync, readFileSync} from "node:fs";
2+
import {urlToHttpOptions} from "node:url";
23
import type * as Models from "../models";
34

45
export function isTcpPath(path: string): boolean {
56
// tcp path must be:
67
// tcp://<host>:<port>
7-
const regex = /^(?:tcp:\/\/)[\w.-]+[:][\d]+$/gm;
8+
const regex = /^(?:tcp:\/\/)\S+?[:]\d+$/gm;
89
return regex.test(path);
910
}
1011

1112
export function parseTcpPath(path: string): {host: string; port: number} {
1213
// built-in extra validation
13-
const info = new URL(path);
14+
const info = urlToHttpOptions(new URL(path));
1415

1516
return {
16-
host: info.hostname,
17+
host: String(info.hostname),
1718
port: Number(info.port),
1819
};
1920
}

0 commit comments

Comments
 (0)