From 922d5da0746732a8cdd20923b53a163ac90c02d7 Mon Sep 17 00:00:00 2001 From: Kuba Orlik Date: Wed, 24 Nov 2021 22:03:03 +0100 Subject: [PATCH] Handle hosts with double-tld better in shorthost method --- package-lock.json | 11 +++++++++++ package.json | 1 + util.ts | 8 ++++---- 3 files changed, 16 insertions(+), 4 deletions(-) diff --git a/package-lock.json b/package-lock.json index 358e097..3229bba 100644 --- a/package-lock.json +++ b/package-lock.json @@ -10,6 +10,7 @@ "license": "ISC", "dependencies": { "@iabtcf/core": "^1.3.1", + "@types/proposal-relative-indexing-method": "^0.1.0", "esbuild": "^0.13.3", "events": "^3.3.0", "react": "^17.0.2", @@ -39,6 +40,11 @@ "integrity": "sha512-rZ5drC/jWjrArrS8BR6SIr4cWpW09RNTYt9AMZo3Jwwif+iacXAqgVjm0B0Bv/S1jhDXKHqRVNCbACkJ89RAnQ==", "dev": true }, + "node_modules/@types/proposal-relative-indexing-method": { + "version": "0.1.0", + "resolved": "https://registry.npmjs.org/@types/proposal-relative-indexing-method/-/proposal-relative-indexing-method-0.1.0.tgz", + "integrity": "sha512-qZHcVIMT0+apQmIPSPG50ksZujLkBE1rYQXVBswF9CcwCGij1zIJemXNdfarqQo5wAhA1K+Y0/h0n5bV8dK7sQ==" + }, "node_modules/@types/react": { "version": "17.0.26", "resolved": "https://registry.npmjs.org/@types/react/-/react-17.0.26.tgz", @@ -386,6 +392,11 @@ "integrity": "sha512-rZ5drC/jWjrArrS8BR6SIr4cWpW09RNTYt9AMZo3Jwwif+iacXAqgVjm0B0Bv/S1jhDXKHqRVNCbACkJ89RAnQ==", "dev": true }, + "@types/proposal-relative-indexing-method": { + "version": "0.1.0", + "resolved": "https://registry.npmjs.org/@types/proposal-relative-indexing-method/-/proposal-relative-indexing-method-0.1.0.tgz", + "integrity": "sha512-qZHcVIMT0+apQmIPSPG50ksZujLkBE1rYQXVBswF9CcwCGij1zIJemXNdfarqQo5wAhA1K+Y0/h0n5bV8dK7sQ==" + }, "@types/react": { "version": "17.0.26", "resolved": "https://registry.npmjs.org/@types/react/-/react-17.0.26.tgz", diff --git a/package.json b/package.json index 3342167..38a4596 100644 --- a/package.json +++ b/package.json @@ -16,6 +16,7 @@ "license": "ISC", "dependencies": { "@iabtcf/core": "^1.3.1", + "@types/proposal-relative-indexing-method": "^0.1.0", "esbuild": "^0.13.3", "events": "^3.3.0", "react": "^17.0.2", diff --git a/util.ts b/util.ts index 6eca30a..d233685 100644 --- a/util.ts +++ b/util.ts @@ -32,12 +32,12 @@ export type Request = { }; export function getshorthost(host: string) { - return host + const parts = host .replace(/^.*:\/\//, "") .replace(/\/.*$/, "") - .split(".") - .slice(-2) - .join("."); + .split("."); + + return parts.slice(parts.at(-2).length > 3 ? -2 : -3).join("."); } export function useEmitter(