From af6d02e59c163d58ad808218a7dd3055c75fd228 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Kilchenmann?= Date: Mon, 12 Jul 2021 17:36:21 +0200 Subject: [PATCH 1/3] fix(ontology): fix regex pattern in ontology form (DSP-1139) --- .../ontology/ontology-form/ontology-form.component.html | 2 +- .../project/ontology/ontology-form/ontology-form.component.ts | 4 +++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/app/project/ontology/ontology-form/ontology-form.component.html b/src/app/project/ontology/ontology-form/ontology-form.component.html index 340c06b1f8..d832103f7e 100644 --- a/src/app/project/ontology/ontology-form/ontology-form.component.html +++ b/src/app/project/ontology/ontology-form/ontology-form.component.html @@ -2,7 +2,7 @@
- help 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 cf60c4c4c6..9fce58c9c5 100644 --- a/src/app/project/ontology/ontology-form/ontology-form.component.ts +++ b/src/app/project/ontology/ontology-form/ontology-form.component.ts @@ -51,8 +51,10 @@ export class OntologyFormComponent implements OnInit { lastModificationDate: string; - nameRegex = /^(?![vV][0-9]|[0-9]|[\u00C0-\u017F]).[a-zA-Z0-9]+\S*$/; + // 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]*$/; + // ontology name must not contain one of the following words forbiddenNames: string[] = [ 'knora', 'salsah', From d214f9be94e829d5eff1eaba5a0305d5b2632f28 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Kilchenmann?= Date: Mon, 12 Jul 2021 21:53:42 +0200 Subject: [PATCH 2/3] fix(ontology): fix regex pattern for onto name --- .../project/ontology/ontology-form/ontology-form.component.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 9fce58c9c5..d90796dfcc 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[] = [ From 546fd18de9be56e29962deb176cbd2ccff63318b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Kilchenmann?= Date: Mon, 12 Jul 2021 21:55:46 +0200 Subject: [PATCH 3/3] test(ontology): test onto name regex pattern --- .../ontology-form.component.spec.ts | 44 +++++++++++++++++++ 1 file changed, 44 insertions(+) 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 b5a7637e82..69983b5435 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 @@ -126,6 +126,50 @@ describe('OntologyFormComponent', () => { }); + it('should test form validity with not allowed names', () => { + const form = ontologyFormComponent.ontologyForm; + expect(form.valid).toBeFalsy(); + + const nameInput = form.controls.name; + + nameInput.setValue('v2onto'); + expect(form.valid).toBeFalsy(); + + nameInput.setValue('my-onto'); + expect(form.valid).toBeFalsy(); + + nameInput.setValue('2ndOnto'); + expect(form.valid).toBeFalsy(); + + nameInput.setValue('-notAllowed'); + expect(form.valid).toBeFalsy(); + + 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(); + + nameInput.setValue('no spaces'); + expect(form.valid).toBeFalsy(); + + nameInput.setValue('ältereOnto'); + expect(form.valid).toBeFalsy(); + + nameInput.setValue('bestOnto'); + expect(form.valid).toBeTruthy(); + + }); + it('should test form validity without label', () => { const form = ontologyFormComponent.ontologyForm; expect(form.valid).toBeFalsy();