diff --git a/client/src/__tests__/helpers.test.ts b/client/src/__tests__/helpers.test.ts index eb165ec0..3dea94ce 100644 --- a/client/src/__tests__/helpers.test.ts +++ b/client/src/__tests__/helpers.test.ts @@ -355,7 +355,23 @@ describe('sortIp', () => { describe('sortAddress', () => { testBaseSortFunction(sortAddress); - describe('mixed_withString', () => { + describe('domain_names_sorting', () => { + test('widcard before other names', () => { + const arr = [ + 'home.fritz.box', + '*.home.fritz.box', + 'adguard-home.fritz.box' + ] + + const sortedArr = [ + '*.home.fritz.box', + 'adguard-home.fritz.box', + 'home.fritz.box' + ]; + + expect(arr.sort(sortAddress)).toStrictEqual(sortedArr); + }) + test('only non-ip strings', () => { const arr = [ 'fritz.box', @@ -392,7 +408,7 @@ describe('sortAddress', () => { expect(arr.sort(sortAddress)).toStrictEqual(sortedArr); }); - test('ipv4, ipv6 in short and long forms and cidr', () => { + test('ipv4, ipv6 in short and long forms and cidr, and a few domain names', () => { const arr = [ '2001:db8:11a3:9d7:0:0:0:1/32', '192.168.1.2', diff --git a/client/src/helpers/helpers.tsx b/client/src/helpers/helpers.tsx index cf6663c1..2fc321be 100644 --- a/client/src/helpers/helpers.tsx +++ b/client/src/helpers/helpers.tsx @@ -793,9 +793,7 @@ const getAddressesComparisonChunks = (address: string, allowOnlyIpAddresses: boo } catch (e) { if (allowOnlyIpAddresses) { - // Rethrowing the exception if only IP addresses and CIDRs are allowed. - // This is to ensure exactly same behavior as in the original code. - throw e + throw new Error(`Invalid address: ${address}. Only IP addresses and CIDRs are allowed.`, { cause: e }); } return [NOT_IP_ADDRESS, address];