فهرست منبع

Merge pull request #7523 from weseek/fix/lsx-filter-and-except

fix: Lsx filter and except option do not work when the path includes special characters
Yuki Takei 3 سال پیش
والد
کامیت
91b4843057
1فایلهای تغییر یافته به همراه5 افزوده شده و 2 حذف شده
  1. 5 2
      packages/remark-lsx/src/server/routes/lsx.js

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

@@ -1,3 +1,4 @@
+import escapeStringRegexp from 'escape-string-regexp';
 import createError, { isHttpError } from 'http-errors';
 import createError, { isHttpError } from 'http-errors';
 
 
 const { pathUtils, pagePathUtils, customTagUtils } = require('@growi/core');
 const { pathUtils, pagePathUtils, customTagUtils } = require('@growi/core');
@@ -103,14 +104,16 @@ class Lsx {
       throw createError(400, 'filter option require value in regular expression.');
       throw createError(400, 'filter option require value in regular expression.');
     }
     }
 
 
+    const pagePathForRegexp = escapeStringRegexp(addTrailingSlash(pagePath));
+
     let filterPath = '';
     let filterPath = '';
     try {
     try {
       if (optionsFilter.charAt(0) === '^') {
       if (optionsFilter.charAt(0) === '^') {
         // move '^' to the first of path
         // move '^' to the first of path
-        filterPath = new RegExp(`^${addTrailingSlash(pagePath)}${optionsFilter.slice(1, optionsFilter.length)}`);
+        filterPath = new RegExp(`^${pagePathForRegexp}${optionsFilter.slice(1, optionsFilter.length)}`);
       }
       }
       else {
       else {
-        filterPath = new RegExp(`^${addTrailingSlash(pagePath)}.*${optionsFilter}`);
+        filterPath = new RegExp(`^${pagePathForRegexp}.*${optionsFilter}`);
       }
       }
     }
     }
     catch (err) {
     catch (err) {