Skip to content

Commit 645e330

Browse files
authored
Corrige le problème des URL avec des espaces à l'intérieur (#623)
* encode & decode pages url * add regex to validate url inputs * validate url fields in a11y statement * update changelog
1 parent 1c29bd8 commit 645e330

5 files changed

Lines changed: 21 additions & 5 deletions

File tree

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@ Tous les changements notables de Ara sont documentés ici avec leur date, leur c
44

55
## 31/01/2024
66

7+
### Corrections 🐛
8+
9+
- Empêche la création de pages avec des espaces dans l’URL ([#623](https://github.com/DISIC/Ara/pull/623))
10+
711
### Autres changements ⚙️
812

913
- Corrige l’accessibilité de l’indicateur d’étape terminée sur la synthèse d’un audit ([#630](https://github.com/DISIC/Ara/pull/630))

confiture-web-app/src/components/audit/AuditGeneralInformationsForm.vue

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import { useNotifications } from "../../composables/useNotifications";
77
import { usePreviousRoute } from "../../composables/usePreviousRoute";
88
import { useAccountStore } from "../../store/account";
99
import { AuditType, CreateAuditRequestData } from "../../types";
10-
import { formatEmail } from "../../utils";
10+
import { formatEmail, URL_REGEX } from "../../utils";
1111
import AuditTypeRadio from "./AuditTypeRadio.vue";
1212
import BackLink from "../ui/BackLink.vue";
1313
import DsfrField from "../ui/DsfrField.vue";
@@ -209,8 +209,7 @@ function onSubmit() {
209209
emit("submit", {
210210
auditType: auditType.value!,
211211
procedureName: procedureName.value,
212-
// remove leading/trailing whitespaces from urls, the browser validation might accept those our backend won't!
213-
pages: pages.value.map((p) => ({ ...p, url: p.url.trim() })),
212+
pages: pages.value.map((p) => ({ ...p, url: p.url })),
214213
auditorName: procedureAuditorName.value,
215214
auditorEmail: formatEmail(procedureAuditorEmail.value)
216215
});
@@ -359,6 +358,8 @@ const previousRoute = usePreviousRoute();
359358
label="URL de la page"
360359
type="url"
361360
required
361+
:pattern="URL_REGEX"
362+
title="https://domaine.fr et sans espaces"
362363
@change="pagesArePristine = false"
363364
>
364365
<template #hint>

confiture-web-app/src/components/ui/DsfrField.vue

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ const props = defineProps<{
77
hint?: string;
88
type?: "text" | "email" | "url";
99
required?: boolean;
10+
pattern?: RegExp;
11+
title?: string;
1012
error?: string;
1113
id: string;
1214
}>();
@@ -39,6 +41,8 @@ defineExpose({ inputRef });
3941
:type="type"
4042
:aria-describedby="isError ? errorId : undefined"
4143
:required="required"
44+
:pattern="pattern ? pattern.toString().slice(1, -1) : undefined"
45+
:title="title"
4246
:value="modelValue"
4347
@input="
4448
$emit('update:modelValue', ($event.target as HTMLInputElement).value)

confiture-web-app/src/pages/audit/AuditDeclarationPage.vue

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import {
1717
} from "../../enums";
1818
import { useAuditStore } from "../../store";
1919
import { AuditEnvironment, UpdateAuditRequestData } from "../../types";
20-
import { formatEmail } from "../../utils";
20+
import { formatEmail, URL_REGEX } from "../../utils";
2121
2222
const route = useRoute();
2323
const uniqueId = route.params.uniqueId as string;
@@ -310,6 +310,8 @@ const isDevMode = useDevMode();
310310
v-model="procedureUrl"
311311
label="URL de la page d’accueil du site audité"
312312
type="url"
313+
:pattern="URL_REGEX"
314+
title="https://domaine.fr et sans espaces"
313315
required
314316
>
315317
<template #hint>
@@ -361,6 +363,8 @@ const isDevMode = useDevMode();
361363
label="Formulaire de contact en ligne"
362364
hint="Exemple : contact@ministere.gouv.fr"
363365
type="url"
366+
:pattern="URL_REGEX"
367+
title="https://domaine.fr et sans espaces"
364368
placeholder="https://"
365369
:error="
366370
hasNoContactInfo

confiture-web-app/src/utils.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,6 @@ export async function captureWithPayloads(
183183
captureException(error, scope);
184184
}
185185

186-
// TODO: use everywhere
187186
export const pluralize = (singular: string, plural: string, count: number) =>
188187
count === 1 ? singular : plural;
189188

@@ -201,6 +200,10 @@ export function formatEmail(s: string): string {
201200
return s.trim().toLocaleLowerCase();
202201
}
203202

203+
// https://regexr.com/7fjmt
204+
export const URL_REGEX =
205+
/^(https?:\/\/)((?!-)(?!.*--)[a-zA-Z\-0-9]{1,63}(?<!-)\.)+[a-zA-Z]{2,63}(\/[^\s]*)?$/;
206+
204207
export function isJwtExpired(jwt: string) {
205208
const payload = jwtDecode<{ exp?: number }>(jwt);
206209

0 commit comments

Comments
 (0)