Files
twenty/packages/twenty-shared/src/utils/url/__tests__/ensureAbsoluteUrl.test.ts
T
Dailin 42269cc45b fix(links): preserve percent-encoded URLs during normalization (#18792)
## Summary

This preserves percent-encoded payloads when normalizing links fields.

`lowercaseUrlOriginAndRemoveTrailingSlash` was decoding the path and
query string while lowercasing the URL origin. That changes URLs where
encoded payloads are semantically significant, such as Google Maps links
containing `%2F` segments.

Closes #18698.

## Changes

- stop decoding the path/query payload in
`lowercaseUrlOriginAndRemoveTrailingSlash`
- preserve the raw path, query, and hash while still lowercasing the
origin and trimming a trailing slash
- update shared URL normalization tests to assert encoded payloads stay
encoded
- add a server-side regression test covering imported links field
normalization

## Validation

- `corepack yarn jest --config packages/twenty-shared/jest.config.mjs
packages/twenty-shared/src/utils/url/__tests__/lowercaseUrlOriginAndRemoveTrailingSlash.test.ts
--runInBand`
- `corepack yarn jest --config packages/twenty-server/jest.config.mjs
packages/twenty-server/src/engine/core-modules/record-transformer/utils/__tests__/transform-links-value.util.spec.ts
--runInBand`
- `corepack yarn nx test twenty-server --runInBand
--testFile=src/engine/core-modules/record-transformer/utils/__tests__/transform-links-value.util.spec.ts`

---------

Co-authored-by: Charles Bochet <charles@twenty.com>
2026-03-20 16:56:12 +00:00

35 lines
1.0 KiB
TypeScript

import { ensureAbsoluteUrl } from '@/utils/url/ensureAbsoluteUrl';
describe('ensureAbsoluteUrl', () => {
it('should return https URL as-is (trimmed)', () => {
expect(ensureAbsoluteUrl('https://example.com')).toBe(
'https://example.com',
);
});
it('should return http URL as-is', () => {
expect(ensureAbsoluteUrl('http://example.com')).toBe('http://example.com');
});
it('should return HTTPS URL as-is', () => {
expect(ensureAbsoluteUrl('HTTPS://example.com')).toBe(
'HTTPS://example.com',
);
});
it('should return HTTP URL as-is', () => {
expect(ensureAbsoluteUrl('HTTP://example.com')).toBe('HTTP://example.com');
});
it('should prepend https:// to bare domains', () => {
expect(ensureAbsoluteUrl('example.com')).toBe('https://example.com');
});
it('should trim whitespace before processing', () => {
expect(ensureAbsoluteUrl(' example.com ')).toBe('https://example.com');
expect(ensureAbsoluteUrl(' https://example.com ')).toBe(
'https://example.com',
);
});
});