From ec881ef60a2c802a2b65a3e047a40d768bc08cf6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Kilchenmann?= Date: Tue, 20 Jul 2021 10:59:50 +0200 Subject: [PATCH] chore(ontology): better regex for onto name (DSP-1139) (#488) * chore(ontology): better regex for onto name (DSP-1139) * test(onto): test new onto name regex (DSP-1139) * chore(ontology): better regex for onto name (DSP-1139) --- .../ontology-form.component.spec.ts | 17 +++++++---------- .../ontology-form/ontology-form.component.ts | 2 +- 2 files changed, 8 insertions(+), 11 deletions(-) diff --git a/src/app/project/ontology/ontology-form/ontology-form.component.spec.ts b/src/app/project/ontology/ontology-form/ontology-form.component.spec.ts index 69983b5435..7f62f05ffe 100644 --- a/src/app/project/ontology/ontology-form/ontology-form.component.spec.ts +++ b/src/app/project/ontology/ontology-form/ontology-form.component.spec.ts @@ -136,7 +136,13 @@ describe('OntologyFormComponent', () => { expect(form.valid).toBeFalsy(); nameInput.setValue('my-onto'); - expect(form.valid).toBeFalsy(); + expect(form.valid).toBeTruthy(); + + nameInput.setValue('my_onto'); + expect(form.valid).toBeTruthy(); + + nameInput.setValue('my.onto'); + expect(form.valid).toBeTruthy(); nameInput.setValue('2ndOnto'); expect(form.valid).toBeFalsy(); @@ -147,15 +153,6 @@ describe('OntologyFormComponent', () => { nameInput.setValue('_notAllowed'); expect(form.valid).toBeFalsy(); - nameInput.setValue('not-allowed'); - expect(form.valid).toBeFalsy(); - - nameInput.setValue('not_allowed'); - expect(form.valid).toBeFalsy(); - - nameInput.setValue('not.allowed'); - expect(form.valid).toBeFalsy(); - nameInput.setValue('no$or€'); expect(form.valid).toBeFalsy(); diff --git a/src/app/project/ontology/ontology-form/ontology-form.component.ts b/src/app/project/ontology/ontology-form/ontology-form.component.ts index d90796dfcc..518846ced4 100644 --- a/src/app/project/ontology/ontology-form/ontology-form.component.ts +++ b/src/app/project/ontology/ontology-form/ontology-form.component.ts @@ -52,7 +52,7 @@ export class OntologyFormComponent implements OnInit { lastModificationDate: string; // regex to check ontology name: shouldn't start with a number or with 'v' followed by a number, spaces or special characters are not allowed - nameRegex = /^(?![vV]+[0-9])+^([a-zA-Z])[a-zA-Z0-9]*$/; + nameRegex = /^(?![vV]+[0-9])+^([a-zA-Z])[a-zA-Z0-9_.-]*$/; // ontology name must not contain one of the following words forbiddenNames: string[] = [