Răsfoiți Sursa

add reg exp try catch

ryoji-s 3 ani în urmă
părinte
comite
cc3b0cdea3
1 a modificat fișierele cu 10 adăugiri și 5 ștergeri
  1. 10 5
      packages/remark-lsx/src/server/routes/lsx.js

+ 10 - 5
packages/remark-lsx/src/server/routes/lsx.js

@@ -104,12 +104,17 @@ class Lsx {
     }
     }
 
 
     let filterPath = '';
     let filterPath = '';
-    if (optionsFilter.charAt(0) === '^') {
-      // move '^' to the first of path
-      filterPath = new RegExp(`^${addTrailingSlash(pagePath)}${optionsFilter.slice(1, optionsFilter.length)}`);
+    try {
+      if (optionsFilter.charAt(0) === '^') {
+        // move '^' to the first of path
+        filterPath = new RegExp(`^${addTrailingSlash(pagePath)}${optionsFilter.slice(1, optionsFilter.length)}`);
+      }
+      else {
+        filterPath = new RegExp(`^${addTrailingSlash(pagePath)}.*${optionsFilter}`);
+      }
     }
     }
-    else {
-      filterPath = new RegExp(`^${addTrailingSlash(pagePath)}.*${optionsFilter}`);
+    catch (err) {
+      throw createError(400, err);
     }
     }
 
 
     if (isExceptFilter) {
     if (isExceptFilter) {