itizawa 5 лет назад
Родитель
Сommit
63344c7647
2 измененных файлов с 9 добавлено и 12 удалено
  1. 8 10
      src/server/models/page.js
  2. 1 2
      src/server/routes/page.js

+ 8 - 10
src/server/models/page.js

@@ -155,10 +155,7 @@ class PageQueryBuilder {
     // eslint-disable-next-line no-param-reassign
     path = addSlashOfEnd(path);
 
-    // add option to escape the regex strings
-    const combinedOption = Object.assign({ isRegExpEscapedFromPath: true }, option);
-
-    this.addConditionToListByStartWith(path, combinedOption);
+    this.addConditionToListByStartWith(path);
 
     return this;
   }
@@ -176,9 +173,12 @@ class PageQueryBuilder {
    * *option*
    *   - isRegExpEscapedFromPath -- if true, the regex strings included in `path` is escaped (default: false)
    */
-  addConditionToListByStartWith(path, option) {
+  addConditionToListByStartWith(path) {
     const pathCondition = [];
-    const isRegExpEscapedFromPath = option.isRegExpEscapedFromPath || false;
+
+    if (path === '/') {
+      return this;
+    }
 
     /*
      * 1. add condition for finding the page completely match with `path` w/o last slash
@@ -192,9 +192,7 @@ class PageQueryBuilder {
     /*
      * 2. add decendants
      */
-    const pattern = (isRegExpEscapedFromPath)
-      ? escapeStringRegexp(path) // escape
-      : pathSlashOmitted;
+    const pattern = escapeStringRegexp(path); // escape
 
     let queryReg;
     try {
@@ -711,7 +709,7 @@ module.exports = function(crowi) {
    */
   pageSchema.statics.findListByStartWith = async function(path, user, option) {
     const builder = new PageQueryBuilder(this.find());
-    builder.addConditionToListByStartWith(path, option);
+    builder.addConditionToListByStartWith(path);
 
     return await findListFromBuilderAndViewer(builder, user, false, option);
   };

+ 1 - 2
src/server/routes/page.js

@@ -280,14 +280,13 @@ module.exports = function(crowi, app) {
     renderVars.slack = await getSlackChannels(page);
   }
 
-  async function addRenderVarsForDescendants(renderVars, path, requestUser, offset, limit, isRegExpEscapedFromPath) {
+  async function addRenderVarsForDescendants(renderVars, path, requestUser, offset, limit) {
     const SEENER_THRESHOLD = 10;
 
     const queryOptions = {
       offset,
       limit,
       includeTrashed: path.startsWith('/trash/'),
-      isRegExpEscapedFromPath,
     };
     const result = await Page.findListWithDescendants(path, requestUser, queryOptions);
     if (result.pages.length > limit) {