From 6bf570ebb53c73e05636b5ac02b784fcb2a6f678 Mon Sep 17 00:00:00 2001 From: Rafael Velazco Date: Thu, 19 Oct 2023 16:54:03 -0400 Subject: [PATCH 1/3] fix: SonarQube regex warning --- .../dot-binary-field-editor.component.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/core-web/libs/contenttype-fields/src/lib/fields/binary-field/components/dot-binary-field-editor/dot-binary-field-editor.component.ts b/core-web/libs/contenttype-fields/src/lib/fields/binary-field/components/dot-binary-field-editor/dot-binary-field-editor.component.ts index f780c97aeb2a..84a6cce6338c 100644 --- a/core-web/libs/contenttype-fields/src/lib/fields/binary-field/components/dot-binary-field-editor/dot-binary-field-editor.component.ts +++ b/core-web/libs/contenttype-fields/src/lib/fields/binary-field/components/dot-binary-field-editor/dot-binary-field-editor.component.ts @@ -81,8 +81,9 @@ export class DotBinaryFieldEditorComponent implements OnInit, AfterViewInit { private extension = ''; private invalidFileMessage = ''; private editor: monaco.editor.IStandaloneCodeEditor; + private readonly regex = new RegExp('^.+\\..+$'); readonly form = new FormGroup({ - name: new FormControl('', [Validators.required, Validators.pattern(/^.+\..+$/)]), + name: new FormControl('', [Validators.required, Validators.pattern(this.regex)]), content: new FormControl('') }); From 5030a427455da1173d1e9a618ec5556b1d3657fa Mon Sep 17 00:00:00 2001 From: Rafael Velazco Date: Thu, 19 Oct 2023 17:01:50 -0400 Subject: [PATCH 2/3] warning: avoid use RegEx --- .../dot-binary-field-editor.component.ts | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/core-web/libs/contenttype-fields/src/lib/fields/binary-field/components/dot-binary-field-editor/dot-binary-field-editor.component.ts b/core-web/libs/contenttype-fields/src/lib/fields/binary-field/components/dot-binary-field-editor/dot-binary-field-editor.component.ts index 84a6cce6338c..4ec615a62842 100644 --- a/core-web/libs/contenttype-fields/src/lib/fields/binary-field/components/dot-binary-field-editor/dot-binary-field-editor.component.ts +++ b/core-web/libs/contenttype-fields/src/lib/fields/binary-field/components/dot-binary-field-editor/dot-binary-field-editor.component.ts @@ -81,9 +81,8 @@ export class DotBinaryFieldEditorComponent implements OnInit, AfterViewInit { private extension = ''; private invalidFileMessage = ''; private editor: monaco.editor.IStandaloneCodeEditor; - private readonly regex = new RegExp('^.+\\..+$'); readonly form = new FormGroup({ - name: new FormControl('', [Validators.required, Validators.pattern(this.regex)]), + name: new FormControl('', [Validators.required, Validators.pattern(/^[^.]+\.[^.]+$/)]), content: new FormControl('') }); From 28a993c3b12b16dd64601a156b159371b8c5204c Mon Sep 17 00:00:00 2001 From: Rafael Velazco Date: Thu, 19 Oct 2023 17:10:43 -0400 Subject: [PATCH 3/3] warning: avoid use RegEx --- .../dot-binary-field-editor.component.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/core-web/libs/contenttype-fields/src/lib/fields/binary-field/components/dot-binary-field-editor/dot-binary-field-editor.component.ts b/core-web/libs/contenttype-fields/src/lib/fields/binary-field/components/dot-binary-field-editor/dot-binary-field-editor.component.ts index 4ec615a62842..63bd3d093f9d 100644 --- a/core-web/libs/contenttype-fields/src/lib/fields/binary-field/components/dot-binary-field-editor/dot-binary-field-editor.component.ts +++ b/core-web/libs/contenttype-fields/src/lib/fields/binary-field/components/dot-binary-field-editor/dot-binary-field-editor.component.ts @@ -142,12 +142,12 @@ export class DotBinaryFieldEditorComponent implements OnInit, AfterViewInit { } private setEditorLanguage(fileName: string = '') { - const fileExtension = fileName?.split('.').pop(); + const fileExtension = fileName?.includes('.') ? fileName.split('.').pop() : ''; const { id, mimetypes, extensions } = this.getLanguage(fileExtension) || {}; this.mimeType = mimetypes?.[0]; this.extension = extensions?.[0]; - if (!this.isValidType()) { + if (fileExtension && !this.isValidType()) { this.name.setErrors({ invalidExtension: this.invalidFileMessage }); }