Skip to content

The open alternative to Salesforce, designed for AI.

Fix logo URL parsing (#28150)

BOHEUS7a70f9571e39
diff --git a/packages/twenty-shared/src/utils/image/__tests__/getLogoUrlFromDomainName.test.ts b/packages/twenty-shared/src/utils/image/__tests__/getLogoUrlFromDomainName.test.ts
index 671e6fb5481..bdcf6cfd7c3 100644
--- a/packages/twenty-shared/src/utils/image/__tests__/getLogoUrlFromDomainName.test.ts
+++ b/packages/twenty-shared/src/utils/image/__tests__/getLogoUrlFromDomainName.test.ts
@@ -42,6 +42,10 @@ describe('getLogoUrlFromDomainName', () => {
expect(getLogoUrlFromDomainName('apple.com')).toBe(
'https://twenty-icons.com/apple.com',
);
+
+ expect(getLogoUrlFromDomainName('https://www.snowww.io')).toBe(
+ 'https://twenty-icons.com/snowww.io',
+ );
});
test('should handle undefined input', () => {
diff --git a/packages/twenty-shared/src/utils/image/getLinkFaviconUrl.ts b/packages/twenty-shared/src/utils/image/getLinkFaviconUrl.ts
index ef1e7751713..b0195446cee 100644
--- a/packages/twenty-shared/src/utils/image/getLinkFaviconUrl.ts
+++ b/packages/twenty-shared/src/utils/image/getLinkFaviconUrl.ts
@@ -1,4 +1,5 @@
import { getLogoUrlFromDomainName } from './getLogoUrlFromDomainName';
+import { isAbsoluteUrl } from '@/utils';
// Resolves a favicon URL from an arbitrary link by extracting the hostname
// first, so paths (e.g. https://linkedin.com/company/twenty) don't leak into
@@ -13,10 +14,7 @@ export const getLinkFaviconUrl = (
return undefined;
}
- const normalized =
- trimmed.startsWith('http://') || trimmed.startsWith('https://')
- ? trimmed
- : `https://${trimmed}`;
+ const normalized = isAbsoluteUrl(trimmed) ? trimmed : `https://${trimmed}`;
try {
const hostname = new URL(normalized).hostname;
diff --git a/packages/twenty-shared/src/utils/image/getLogoUrlFromDomainName.ts b/packages/twenty-shared/src/utils/image/getLogoUrlFromDomainName.ts
index 871204ffea7..a590e66b4c4 100644
--- a/packages/twenty-shared/src/utils/image/getLogoUrlFromDomainName.ts
+++ b/packages/twenty-shared/src/utils/image/getLogoUrlFromDomainName.ts
@@ -1,6 +1,9 @@
export const sanitizeURL = (link: string | null | undefined) => {
return link
- ? link.replace(/(https?:\/\/)|(www\.)/g, '').replace(/\/$/, '')
+ ? link
+ .replace(/(^https?:\/\/)/i, '')
+ .replace(/(^www\.)/i, '')
+ .replace(/\/$/, '')
: '';
};
diff --git a/packages/twenty-shared/src/utils/url/ensureAbsoluteUrl.ts b/packages/twenty-shared/src/utils/url/ensureAbsoluteUrl.ts
index 4f1d2d7db0a..920ef4c7ae0 100644
--- a/packages/twenty-shared/src/utils/url/ensureAbsoluteUrl.ts
+++ b/packages/twenty-shared/src/utils/url/ensureAbsoluteUrl.ts
@@ -1,12 +1,9 @@
+import { isAbsoluteUrl } from '@/utils';
+
export const ensureAbsoluteUrl = (value: string): string => {
const trimmedValue = value.trim();
- if (
- trimmedValue.startsWith('http://') ||
- trimmedValue.startsWith('https://') ||
- trimmedValue.startsWith('HTTPS://') ||
- trimmedValue.startsWith('HTTP://')
- ) {
+ if (isAbsoluteUrl(trimmedValue)) {
return trimmedValue;
}