cope with specchial chars in js regExp
authorCornelius Weiß <c.weiss@metaways.de>
Wed, 12 Jul 2017 17:32:56 +0000 (19:32 +0200)
committerPhilipp Schüle <p.schuele@metaways.de>
Wed, 12 Jul 2017 17:47:40 +0000 (19:47 +0200)
Change-Id: I7da1ef2c6445b7271aa929a4c817617f6341ad5e
Reviewed-on: http://gerrit.tine20.com/customers/5132
Reviewed-by: Philipp Schüle <p.schuele@metaways.de>
Tested-by: Philipp Schüle <p.schuele@metaways.de>
12 files changed:
tine20/Felamimail/js/FolderStore.js
tine20/Felamimail/js/MessageEditDialog.js
tine20/Filemanager/js/NodeTreePanel.js
tine20/Filemanager/js/nodeActions.js
tine20/MailFiler/js/nodeActions.js
tine20/Tinebase/js/CanonicalPath.js
tine20/Tinebase/js/Container.js
tine20/Tinebase/js/tineInit.js
tine20/Tinebase/js/widgets/ActivitiesPanel.js
tine20/Tinebase/js/widgets/dialog/EditDialog.js
tine20/Tinebase/js/widgets/keyfield/ComboBox.js
tine20/Tinebase/js/widgets/path/renderer.js

index e21c1b0..6b28137 100644 (file)
@@ -71,7 +71,7 @@ Ext.extend(Tine.Felamimail.FolderStore, Ext.data.Store, {
         if (store.queriesDone.indexOf(key) >= 0) {
             Tine.log.debug('result already loaded -> directly query store');
             // we need regexp here because query returns all records with path that begins with the value string otherwise
-            var valueReg = new RegExp(value + '$');
+            var valueReg = new RegExp(window.lodash.escapeRegExp(value) + '$');
             result = store.query(field, valueReg);
             args.push(result);
             callback.apply(scope, args);
index a48794f..bd220c2 100644 (file)
@@ -642,7 +642,7 @@ Tine.Felamimail.MessageEditDialog = Ext.extend(Tine.widgets.dialog.EditDialog, {
             
             // remove own email and all non-email strings/objects from to/cc
             var account = Tine.Tinebase.appMgr.get('Felamimail').getAccountStore().getById(this.record.get('account_id')),
-                ownEmailRegexp = new RegExp(account.get('email'));
+                ownEmailRegexp = new RegExp(window.lodash.escapeRegExp(account.get('email')));
             Ext.each(['to', 'cc'], function(field) {
                 for (var i=0; i < this[field].length; i++) {
                     if (! Ext.isString(this[field][i]) || ! this[field][i].match(/@/) || ownEmailRegexp.test(this[field][i])) {
index 8b6fc62..79a0650 100644 (file)
@@ -76,9 +76,10 @@ Tine.Filemanager.NodeTreePanel = Ext.extend(Tine.widgets.container.TreePanel, {
 
     onRecordChanges: function(data, e) {
         if (data.type == 'folder') {
-            var me = this,
+            var _ = window.lodash,
+                me = this,
                 path = data.path,
-                parentPath = path.replace(new RegExp(data.name + '$'), ''),
+                parentPath = path.replace(new RegExp(_.escapeRegExp(data.name) + '$'), ''),
                 node = this.getNodeById(data.id),
                 pathChange = node && node.attributes && node.attributes.nodeRecord.get('path') != path;
 
@@ -366,8 +367,9 @@ Tine.Filemanager.NodeTreePanel = Ext.extend(Tine.widgets.container.TreePanel, {
      * @return {String} tree path
      */
     getTreePath: function(containerPath) {
-        var treePath = '/' + this.getRootNode().id + containerPath
-            .replace(new RegExp('^' + Tine.Tinebase.container.getMyFileNodePath()), '/myUser')
+        var _ = window.lodash,
+            treePath = '/' + this.getRootNode().id + containerPath
+            .replace(new RegExp('^' + _.escapeRegExp(Tine.Tinebase.container.getMyFileNodePath())), '/myUser')
             .replace(/^\/personal/, '/otherUsers')
             .replace(/\/$/, '');
 
index 2220877..71bf5be 100644 (file)
@@ -140,7 +140,7 @@ Tine.Filemanager.nodeActions.Rename = {
                     }
 
                     // @TODO validate filename
-                    var targetPath = record.get('path').replace(new RegExp(record.get('name') +'$'), text);
+                    var targetPath = record.get('path').replace(new RegExp(_.escapeRegExp(record.get('name')) +'$'), text);
                     Tine.Filemanager.fileRecordBackend.copyNodes([record], targetPath, true);
 
                 }
index d275cb9..167bc03 100644 (file)
@@ -129,7 +129,7 @@ Tine.MailFiler.nodeActions.Rename = {
                     }
 
                     // @TODO validate filename
-                    var targetPath = record.get('path').replace(new RegExp(record.get('name') +'$'), text);
+                    var targetPath = record.get('path').replace(_.escapeRegExp(new RegExp(record.get('name')) +'$'), text);
                     Tine.MailFiler.fileRecordBackend.copyNodes([record], targetPath, true);
 
                 }
index 1aaefbe..f351e84 100644 (file)
@@ -20,13 +20,14 @@ Tine.Tinebase.CanonicalPath.separator = '/';
  * @param {Ext.Component} component
  */
 Tine.Tinebase.CanonicalPath.getPath = function(component) {
-    var pathParts = [],
+    var _ = window.lodash,
+        pathParts = [],
         pathPart;
 
     while (component) {
         pathPart = Tine.Tinebase.CanonicalPath.getPathPart(component);
 
-        if (pathPart && !pathParts.join(Tine.Tinebase.CanonicalPath.separator).match(new RegExp('^' + pathPart))) {
+        if (pathPart && !pathParts.join(Tine.Tinebase.CanonicalPath.separator).match(new RegExp('^' + _.escapeRegExp(pathPart)))) {
             pathParts.unshift(pathPart);
         }
 
index a338c5e..e79aec9 100644 (file)
@@ -87,7 +87,7 @@ Tine.Tinebase.container = {
      * @return {Boolean}
      */
     pathIsMyPersonalContainer: function(path) {
-        var regExp = new RegExp('^' + Tine.Tinebase.container.getMyNodePath() + '\/([0-9a-z_\-]+)$');
+        var regExp = new RegExp('^' + window.lodash.escapeRegExp(Tine.Tinebase.container.getMyNodePath()) + '\/([0-9a-z_\-]+)$');
         var matches = String(path).match(regExp);
         
         return !!matches;
index bab4271..c59b847 100644 (file)
@@ -146,7 +146,7 @@ Tine.Tinebase.tineInit = {
             var target = e.getTarget('a',1 ,true);
             if (target && target.getAttribute('target') == '_blank') {
                 var href = String(target.getAttribute('href'));
-                    if (href.match(new RegExp('^' + Tine.Tinebase.common.getUrl()))) {
+                    if (href.match(new RegExp('^' + window.lodash.escapeRegExp(Tine.Tinebase.common.getUrl())))) {
                         target.set({
                             href: decodeURI(href),
                             target: "_self"
index fb79722..12b9496 100644 (file)
@@ -128,8 +128,9 @@ Tine.widgets.activities.ActivitiesTabPanel = Ext.extend(Ext.Panel, {
 
         if (recordClass) {
             Ext.each(recordClass.getFieldDefinitions(), function(field) {
-                var i18nLabel = field.label ? i18n._hidden(field.label) : field.name,
-                    regexp = new RegExp(' (' + field.name +'|' + i18nLabel + ') \\((.*) (->) ([^)]*)\\)'),
+                var _ = window.lodash,
+                    i18nLabel = field.label ? i18n._hidden(field.label) : field.name,
+                    regexp = new RegExp(' (' + _.escapeRegExp(field.name) +'|' + _.escapeRegExp(i18nLabel) + ') \\((.*) (->) ([^)]*)\\)'),
                     struct = regexp.exec(note),
                     label = struct && struct.length == 5 ? struct[1] : null,
                     oldValue = label ? struct[2] : null,
index 8735556..4391e7a 100644 (file)
@@ -891,7 +891,7 @@ Tine.widgets.dialog.EditDialog = Ext.extend(Ext.FormPanel, {
 
         this.checkStates.defer(100, this);
 
-        if (this.loadMask) {
+        if (this.loadMask && !this.saving) {
             this.loadMask.hide();
         }
     },
@@ -1108,13 +1108,14 @@ Tine.widgets.dialog.EditDialog = Ext.extend(Ext.FormPanel, {
     
     onAfterApplyChanges: function(closeWindow) {
         this.window.rename(this.windowNamePrefix + this.record.id);
-        this.loadMask.hide();
         this.saving = false;
         
         if (closeWindow) {
             this.window.fireEvent('saveAndClose');
             this.purgeListeners();
             this.window.close();
+        } else {
+            this.loadMask.hide();
         }
     },
     
index e1c3f8a..ea56340 100644 (file)
@@ -103,7 +103,7 @@ Tine.Tinebase.widgets.keyfield.ComboBox = Ext.extend(Ext.form.ComboBox, {
     applyParentValue: function(parentValue){
         this.store.filter('id', parentValue);
 
-        var parentRe = new RegExp('^' + parentValue),
+        var parentRe = new RegExp('^' + window.lodash.escapeRegExp(parentValue)),
             defaultValues = this.keyFieldConfig && Ext.isObject(this.keyFieldConfig.value) && this.keyFieldConfig.value.hasOwnProperty('default') ? this.keyFieldConfig.value['default'] : false,
             defaultValue = '';
 
index d434e07..db24e3d 100644 (file)
@@ -51,7 +51,7 @@ Tine.widgets.path.pathRenderer = function(path, queryString) {
             search = '';
 
         Ext.each(queryParts, function(queryPart, idx) {
-            search += (search ? '|(' :'(') + Ext.util.Format.htmlEncode(queryPart) + ')';
+            search += (search ? '|(' :'(') + window.lodash.escapeRegExp(queryPart) + ')';
         });
 
         pathName = pathName.replace(new RegExp(search,'gi'), function(match) {