|
@@ -713,6 +713,7 @@ module.exports = function(crowi) {
|
|
|
|
|
|
|
|
// ignore other pages than descendants
|
|
// ignore other pages than descendants
|
|
|
path = Page.addSlashOfEnd(path);
|
|
path = Page.addSlashOfEnd(path);
|
|
|
|
|
+
|
|
|
// add option to escape the regex strings
|
|
// add option to escape the regex strings
|
|
|
const combinedOption = Object.assign({isRegExpEscapedFromPath: true}, option);
|
|
const combinedOption = Object.assign({isRegExpEscapedFromPath: true}, option);
|
|
|
|
|
|
|
@@ -722,8 +723,12 @@ module.exports = function(crowi) {
|
|
|
/**
|
|
/**
|
|
|
* generate the query to find pages that start with `path`
|
|
* generate the query to find pages that start with `path`
|
|
|
*
|
|
*
|
|
|
- * If `path` has `/` at the end, returns '{path}/*' and '{path}' self.
|
|
|
|
|
- * If `path` doesn't have `/` at the end, returns '{path}*'
|
|
|
|
|
|
|
+ * (GROWI) If 'isRegExpEscapedFromPath' is true, `path` should have `/` at the end
|
|
|
|
|
+ * -> returns '{path}/*' and '{path}' self.
|
|
|
|
|
+ * (Crowi) If 'isRegExpEscapedFromPath' is false and `path` has `/` at the end
|
|
|
|
|
+ * -> returns '{path}*'
|
|
|
|
|
+ * (Crowi) If 'isRegExpEscapedFromPath' is false and `path` doesn't have `/` at the end
|
|
|
|
|
+ * -> returns '{path}*'
|
|
|
*
|
|
*
|
|
|
* *option*
|
|
* *option*
|
|
|
* - includeDeletedPage -- if true, search deleted pages (default: false)
|
|
* - includeDeletedPage -- if true, search deleted pages (default: false)
|
|
@@ -735,17 +740,22 @@ module.exports = function(crowi) {
|
|
|
var includeDeletedPage = option.includeDeletedPage || false;
|
|
var includeDeletedPage = option.includeDeletedPage || false;
|
|
|
var isRegExpEscapedFromPath = option.isRegExpEscapedFromPath || false;
|
|
var isRegExpEscapedFromPath = option.isRegExpEscapedFromPath || false;
|
|
|
|
|
|
|
|
|
|
+ /*
|
|
|
|
|
+ * 1. add condition for finding the page completely match with `path` w/o last slash
|
|
|
|
|
+ */
|
|
|
let pathSlashOmitted = path;
|
|
let pathSlashOmitted = path;
|
|
|
if (path.match(/\/$/)) {
|
|
if (path.match(/\/$/)) {
|
|
|
- // add condition for finding the page completely match with `path`
|
|
|
|
|
pathSlashOmitted = path.substr(0, path.length -1);
|
|
pathSlashOmitted = path.substr(0, path.length -1);
|
|
|
pathCondition.push({path: pathSlashOmitted});
|
|
pathCondition.push({path: pathSlashOmitted});
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- // create forward match pattern
|
|
|
|
|
|
|
+ /*
|
|
|
|
|
+ * 2. add decendants
|
|
|
|
|
+ */
|
|
|
var pattern = (isRegExpEscapedFromPath)
|
|
var pattern = (isRegExpEscapedFromPath)
|
|
|
- ? escapeStringRegexp(pathSlashOmitted) // escape
|
|
|
|
|
|
|
+ ? escapeStringRegexp(path) // escape
|
|
|
: pathSlashOmitted;
|
|
: pathSlashOmitted;
|
|
|
|
|
+
|
|
|
var queryReg = new RegExp('^' + pattern);
|
|
var queryReg = new RegExp('^' + pattern);
|
|
|
pathCondition.push({path: queryReg});
|
|
pathCondition.push({path: queryReg});
|
|
|
|
|
|