Skip to content

Commit

Permalink
MAJ de la validation des champs URL (#727)
Browse files Browse the repository at this point in the history
* update url regex

* update dtos for url

* remove title attribute on url fields

* update changelog
  • Loading branch information
bellangerq authored Jun 6, 2024
1 parent 821fba8 commit 7a477c4
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 19 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ Tous les changements notables de Ara sont documentés ici avec leur date, leur c
### Corrections 🐛

- Corrige un problème du filtre de conformité des critères ([#726](https://github.com/DISIC/Ara/pull/726))
- Corrige la validation des champs URL pour être plus flexible ([#727](https://github.com/DISIC/Ara/pull/727))

## 05/06/2024

Expand Down
3 changes: 1 addition & 2 deletions confiture-rest-api/src/audits/dto/create-audit.dto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import {
IsNumber,
IsOptional,
IsString,
IsUrl,
ValidateNested
} from "class-validator";

Expand All @@ -28,7 +27,7 @@ export class CreateAuditPage {
/**
* @example "https://example.com/contact"
*/
@IsUrl()
@IsString()
url: string;
}

Expand Down
5 changes: 2 additions & 3 deletions confiture-rest-api/src/audits/dto/update-audit.dto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import {
IsEmail,
IsOptional,
IsString,
IsUrl,
ValidateNested
} from "class-validator";

Expand Down Expand Up @@ -75,7 +74,7 @@ export class UpdateAuditDto extends CreateAuditDto {
/**
* @example "https://procedure.government.com"
*/
@IsUrl()
@IsString()
@IsOptional()
procedureUrl?: string;

Expand Down Expand Up @@ -110,7 +109,7 @@ export class UpdateAuditDto extends CreateAuditDto {
/**
* @example "https://procedure.government.com/contact-a11y"
*/
@IsUrl()
@IsString()
@IsOptional()
contactFormUrl?: string;

Expand Down
6 changes: 3 additions & 3 deletions confiture-web-app/src/components/audit/PagesSample.vue
Original file line number Diff line number Diff line change
Expand Up @@ -165,13 +165,13 @@ function updatePageOrder(startIndex: number, endIndex: number) {
:id="`page-url-${i + 1}`"
v-model="page.url"
label="URL de la page"
type="url"
type="text"
required
:pattern="URL_REGEX"
title="https://domaine.fr et sans espaces"
>
<template #hint>
L’URL de la page doit commencer par <code>https://</code>
L’URL de la page doit commencer par <code>https://</code> ou
<code>http://</code>
</template>
</DsfrField>
</fieldset>
Expand Down
14 changes: 6 additions & 8 deletions confiture-web-app/src/pages/audit/AuditDeclarationPage.vue
Original file line number Diff line number Diff line change
Expand Up @@ -317,14 +317,13 @@ const isDevMode = useDevMode();
id="procedure-url"
v-model="procedureUrl"
label="URL de la page d’accueil du site audité"
type="url"
type="text"
:pattern="URL_REGEX"
title="https://domaine.fr et sans espaces"
required
>
<template #hint>
Saisissez une url valide, commençant par
<code>https://</code>
Saisissez une URL valide, commençant par
<code>https://</code> ou <code>http://</code>
</template>
</DsfrField>

Expand Down Expand Up @@ -370,9 +369,8 @@ const isDevMode = useDevMode();
v-model="contactFormUrl"
label="Formulaire de contact en ligne"
hint="Exemple : [email protected]"
type="url"
type="text"
:pattern="URL_REGEX"
title="https://domaine.fr et sans espaces"
placeholder="https://"
:error="
hasNoContactInfo
Expand All @@ -381,8 +379,8 @@ const isDevMode = useDevMode();
"
>
<template #hint>
Saisissez une URL valide, commençant par <code>http://</code> ou
<code>https://</code>
Saisissez une URL valide, commençant par <code>https://</code> ou
<code>http://</code>
</template>
</DsfrField>
</fieldset>
Expand Down
5 changes: 2 additions & 3 deletions confiture-web-app/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -191,9 +191,8 @@ export function formatEmail(s: string): string {
return s.trim().toLocaleLowerCase();
}

// https://regexr.com/7fjmt
export const URL_REGEX =
/^(https?:\/\/)((?!-)(?!.*--)[a-zA-Z\-0-9]{1,63}(?<!-)\.)+[a-zA-Z]{2,63}(\/[^\s]*)?$/;
// https://regexr.com/819do
export const URL_REGEX = /^https?:\/\/(.*)/;

export function isJwtExpired(jwt: string) {
const payload = jwtDecode<{ exp?: number }>(jwt);
Expand Down

0 comments on commit 7a477c4

Please sign in to comment.