popojargo commented on a change in pull request #1137: Validate regex on client 
side.
URL: https://github.com/apache/couchdb-fauxton/pull/1137#discussion_r224442605
 
 

 ##########
 File path: app/addons/documents/mango/components/MangoQueryEditor.js
 ##########
 @@ -130,16 +131,54 @@ export default class MangoQueryEditor extends Component {
   notifyOnQueryError() {
     if (this.editorHasErrors()) {
       FauxtonAPI.addNotification({
-        msg:  'Please fix the Javascript errors and try again.',
+        msg:  'Please fix the JSON errors and try again.',
         type: 'error',
         clear: true
       });
 
       return true;
     }
+
     return false;
   }
 
+  getJsonIfValid(json) {
+    try {
+      return JSON.parse(json);
+    } catch (e) {
+      FauxtonAPI.addNotification({
+        msg:  'Please fix the JSON errors and try again. Error: ' + e.message,
+        type: 'error',
+        clear: true
+      });
+    }
+  }
+
+  isRegexValid(selector = {}) {
+    const regexes = Helper.getSelectorRegexes(selector);
+    const errors = _.reduce(regexes, (acc, val) => {
+      try {
+        new RegExp(val);
 
 Review comment:
   See the linked issue. I guess the best solution would be to have more human 
friendly error message when having regex errors. If that's not possible, I 
could allow to send wrong regex to the server and use my code to return more 
detailed error message in case of failure

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
[email protected]


With regards,
Apache Git Services

Reply via email to