Removing trailing slashes (#12658)

Fix inconsistent domain URL formats : removing the last / that was
caused by URL method

Standardize URL formatting to ensure consistent links storage and
retrieval of domain URLs across the application. Will improve the
dedpulicates in the links

Note: there is another temporary issue from google that was solved on
the 13th of june https://groups.google.com/g/adwords-api/c/tRSQMRZrJYM
but we consider this out of this scope

Fixes #12621
This commit is contained in:
Guillim
2025-06-17 16:29:14 +02:00
committed by GitHub
parent cc7a37b0cc
commit 1cee587709
14 changed files with 414 additions and 70 deletions

View File

@ -8,7 +8,9 @@ export const absoluteUrlSchema = z.string().transform((value, ctx) => {
const valueWithoutProtocol = absoluteUrl
.replace('https://', '')
.replace('http://', '');
.replace('http://', '')
.replace('HTTPS://', '')
.replace('HTTP://', '');
if (/^\d+(?:\/[a-zA-Z]*)?$/.test(valueWithoutProtocol)) {
// if the hostname is a number, it's not a valid url
@ -20,14 +22,11 @@ export const absoluteUrlSchema = z.string().transform((value, ctx) => {
return z.NEVER;
}
try {
const url = new URL(absoluteUrl);
if (isValidHostname(url.hostname)) {
return absoluteUrl;
}
ctx.addIssue({
code: z.ZodIssueCode.custom,
message: 'domain is not a valid url',

View File

@ -1,5 +1,10 @@
export const getAbsoluteUrl = (value: string): string => {
if (value.startsWith('http://') || value.startsWith('https://')) {
if (
value.startsWith('http://') ||
value.startsWith('https://') ||
value.startsWith('HTTPS://') ||
value.startsWith('HTTP://')
) {
return value;
}