@@ -32,24 +32,6 @@ export function getJWTIssuer(token: string): string | null {
3232 return payload.iss;
3333}
3434
35- /**
36- * Compares two host URLs, ignoring ports.
37- * Treats "example.com" and "example.com:443" as equivalent.
38- *
39- * @param url1 - First URL or hostname
40- * @param url2 - Second URL or hostname
41- * @returns true if the hosts are the same
42- */
43- export function isSameHost(url1: string, url2: string): boolean {
44- try {
45- const host1 = extractHostname(url1);
46- const host2 = extractHostname(url2);
47- return host1.toLowerCase() === host2.toLowerCase();
48- } catch {
49- return false;
50- }
51- }
52-
5335/**
5436 * Extracts the hostname from a URL or hostname string.
5537 * Handles both full URLs and bare hostnames.
@@ -64,7 +46,7 @@ function extractHostname(urlOrHostname: string): string {
6446 return url.hostname;
6547 }
6648
67- // Handle hostname with port (e.g., "example .com:443")
49+ // Handle hostname with port (e.g., "databricks .com:443")
6850 const colonIndex = urlOrHostname.indexOf(':');
6951 if (colonIndex !== -1) {
7052 return urlOrHostname.substring(0, colonIndex);
@@ -73,3 +55,25 @@ function extractHostname(urlOrHostname: string): string {
7355 // Bare hostname
7456 return urlOrHostname;
7557}
58+
59+ /**
60+ * Compares two host URLs, ignoring ports.
61+ * Treats "databricks.com" and "databricks.com:443" as equivalent.
62+ *
63+ * @param url1 - First URL or hostname
64+ * @param url2 - Second URL or hostname
65+ * @returns true if the hosts are the same
66+ */
67+ export function isSameHost(url1: string, url2: string): boolean {
68+ try {
69+ const host1 = extractHostname(url1);
70+ const host2 = extractHostname(url2);
71+ // Empty hostnames are not valid
72+ if (!host1 || !host2) {
73+ return false;
74+ }
75+ return host1.toLowerCase() === host2.toLowerCase();
76+ } catch {
77+ return false;
78+ }
79+ }
0 commit comments