]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
mgr/dashboard: Escape regex pattern in DeletionModalComponent 23420/head
authorTiago Melo <tspmelo@gmail.com>
Fri, 3 Aug 2018 17:47:59 +0000 (18:47 +0100)
committerTiago Melo <tspmelo@gmail.com>
Mon, 6 Aug 2018 08:57:18 +0000 (09:57 +0100)
Fixes: http://tracker.ceph.com/issues/24902
Signed-off-by: Tiago Melo <tmelo@suse.com>
src/pybind/mgr/dashboard/frontend/src/app/shared/components/deletion-modal/deletion-modal.component.html
src/pybind/mgr/dashboard/frontend/src/app/shared/components/deletion-modal/deletion-modal.component.spec.ts
src/pybind/mgr/dashboard/frontend/src/app/shared/components/deletion-modal/deletion-modal.component.ts

index 365686522c5b2d1d79bb9ea4148244807712e98a..ca2f4ca5138dea91e845f340c9aece53e95246e9 100644 (file)
@@ -30,7 +30,7 @@
                  name="confirmation"
                  id="confirmation"
                  [placeholder]="pattern"
-                 [pattern]="pattern"
+                 [pattern]="escapeRegExp(pattern)"
                  autocomplete="off"
                  (keyup)="updateConfirmation($event)"
                  formControlName="confirmation"
index 8bb94293eabde6eac6a6c47f500a1b8da1c49be6..e1abdb037395abe1d5ab3e36f2830959e0d96dde 100644 (file)
@@ -286,6 +286,14 @@ describe('DeletionModalComponent', () => {
         testValidation(false, undefined, false);
         testValidation(true, undefined, false);
       });
+
+      it('should test regex pattern', () => {
+        component.pattern = 'a+b';
+        changeValue('ab');
+        testValidation(false, 'pattern', true);
+        changeValue('a+b');
+        testValidation(false, 'pattern', false);
+      });
     });
 
     describe('deletion call', () => {
index caf9d08b38f05802a85c96da88bbb3aef54fafea..4eaab360650069d42d62b529dbfa1940cd403c03 100644 (file)
@@ -93,4 +93,8 @@ export class DeletionModalComponent implements OnInit {
   stopLoadingSpinner() {
     this.deletionForm.setErrors({ cdSubmitButton: true });
   }
+
+  escapeRegExp(text) {
+    return text.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
+  }
 }