Skip to content

Commit

Permalink
fix(ignore): improve e9240da
Browse files Browse the repository at this point in the history
  • Loading branch information
Koenkk committed Dec 5, 2024
1 parent e9240da commit 5a29fda
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
8 changes: 5 additions & 3 deletions src/adapter/adapterDiscovery.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import assert from 'assert';
import {platform} from 'os';

import {PortInfo} from '@serialport/bindings-cpp';
Expand Down Expand Up @@ -460,9 +461,10 @@ export async function findmDNSAdapter(path: string): Promise<[adapter: Adapter,
}

export async function findTCPAdapter(path: string, adapter?: Adapter): Promise<[adapter: Adapter, path: string]> {
const regex = /^(tcp|socket):\/\/.+:\d{1,5}$/gm;

if (!regex.test(path)) {
try {
const url = new URL(path);
assert(url.port !== '');
} catch {
throw new Error(`Invalid TCP path, expected format: tcp://<host>:<port>`);
}

Expand Down
4 changes: 2 additions & 2 deletions test/adapter/adapter.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -190,9 +190,9 @@ describe('Adapter', () => {
});
});

it('invalid path', async () => {
test.each([`tcp://192168.1.321`, `tcp://192168.1.321:INVALID`])('invalid path', async (path) => {
expect(async () => {
await Adapter.create({panID: 0x1a62, channelList: [11]}, {path: `tcp://192168.1.321:INVALID`, adapter: `zstack`}, 'test.db.backup', {
await Adapter.create({panID: 0x1a62, channelList: [11]}, {path, adapter: `zstack`}, 'test.db.backup', {
disableLED: false,
});
}).rejects.toThrow(`Invalid TCP path, expected format: tcp://<host>:<port>`);
Expand Down

0 comments on commit 5a29fda

Please sign in to comment.