|
@@ -6,7 +6,6 @@ import mongoose, {
|
|
|
import mongoosePaginate from 'mongoose-paginate-v2';
|
|
import mongoosePaginate from 'mongoose-paginate-v2';
|
|
|
import uniqueValidator from 'mongoose-unique-validator';
|
|
import uniqueValidator from 'mongoose-unique-validator';
|
|
|
import nodePath from 'path';
|
|
import nodePath from 'path';
|
|
|
-import RE2 from 're2';
|
|
|
|
|
|
|
|
|
|
import { getOrCreateModel, pagePathUtils } from '@growi/core';
|
|
import { getOrCreateModel, pagePathUtils } from '@growi/core';
|
|
|
import loggerFactory from '../../utils/logger';
|
|
import loggerFactory from '../../utils/logger';
|
|
@@ -113,19 +112,6 @@ const hasSlash = (str: string): boolean => {
|
|
|
return str.includes('/');
|
|
return str.includes('/');
|
|
|
};
|
|
};
|
|
|
|
|
|
|
|
-/*
|
|
|
|
|
- * Generate RE2 instance for one level lower path
|
|
|
|
|
- */
|
|
|
|
|
-const generateChildrenRE2 = (path: string): RE2 => {
|
|
|
|
|
- // https://regex101.com/r/laJGzj/1
|
|
|
|
|
- // ex. /any_level1
|
|
|
|
|
- if (isTopPage(path)) return new RE2(/^\/[^/]+$/);
|
|
|
|
|
-
|
|
|
|
|
- // https://regex101.com/r/mrDJrx/1
|
|
|
|
|
- // ex. /parent/any_child OR /any_level1
|
|
|
|
|
- return new RE2(`^${path}(\\/[^/]+)\\/?$`);
|
|
|
|
|
-};
|
|
|
|
|
-
|
|
|
|
|
/*
|
|
/*
|
|
|
* Generate RegExp instance for one level lower path
|
|
* Generate RegExp instance for one level lower path
|
|
|
*/
|
|
*/
|
|
@@ -300,8 +286,8 @@ schema.statics.findChildrenByParentPathOrIdAndViewer = async function(parentPath
|
|
|
let queryBuilder: PageQueryBuilder;
|
|
let queryBuilder: PageQueryBuilder;
|
|
|
if (hasSlash(parentPathOrId)) {
|
|
if (hasSlash(parentPathOrId)) {
|
|
|
const path = parentPathOrId;
|
|
const path = parentPathOrId;
|
|
|
- const regexp = generateChildrenRE2(path);
|
|
|
|
|
- queryBuilder = new PageQueryBuilder(this.find({ path: { $regex: regexp.source } }), true);
|
|
|
|
|
|
|
+ const regexp = generateChildrenRegExp(path);
|
|
|
|
|
+ queryBuilder = new PageQueryBuilder(this.find({ path: { $regex: regexp } }), true);
|
|
|
}
|
|
}
|
|
|
else {
|
|
else {
|
|
|
const parentId = parentPathOrId;
|
|
const parentId = parentPathOrId;
|