|
|
@@ -611,26 +611,22 @@ module.exports = function(crowi) {
|
|
|
|
|
|
/**
|
|
|
* find the page that is match with `path` and its descendants
|
|
|
- *
|
|
|
- * 1. `/` will be added to the end of `path`
|
|
|
- * 2. the regex strings included in `path` will be escaped
|
|
|
*/
|
|
|
pageSchema.statics.findListWithDescendants = function(path, userData, option) {
|
|
|
var Page = this;
|
|
|
|
|
|
- // add slash to the last
|
|
|
+ // ignore other pages than descendants
|
|
|
path = Page.addSlashOfEnd(path);
|
|
|
- // escape
|
|
|
- path = escapeStringRegexp(path);
|
|
|
+ // add option to escape the regex strings
|
|
|
+ const combinedOption = Object.assign({isRegExpEscapedFromPath: true}, option);
|
|
|
|
|
|
- return Page.findListByStartWith(path, userData, option);
|
|
|
+ return Page.findListByStartWith(path, userData, combinedOption);
|
|
|
};
|
|
|
|
|
|
/**
|
|
|
* 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}*'
|
|
|
+ * see the comment of `generateQueryToListByStartWith` function
|
|
|
*/
|
|
|
pageSchema.statics.findListByStartWith = function(path, userData, option) {
|
|
|
var Page = this;
|
|
|
@@ -675,19 +671,16 @@ module.exports = function(crowi) {
|
|
|
|
|
|
/**
|
|
|
* generate the query to find the page that is match with `path` and its descendants
|
|
|
- *
|
|
|
- * 1. `/` will be added to the end of `path`
|
|
|
- * 2. the regex strings included in `path` will be escaped
|
|
|
*/
|
|
|
pageSchema.statics.generateQueryToListWithDescendants = function(path, userData, option) {
|
|
|
var Page = this;
|
|
|
|
|
|
- // add slash to the last
|
|
|
+ // ignore other pages than descendants
|
|
|
path = Page.addSlashOfEnd(path);
|
|
|
- // escape
|
|
|
- path = escapeStringRegexp(path);
|
|
|
+ // add option to escape the regex strings
|
|
|
+ const combinedOption = Object.assign({isRegExpEscapedFromPath: true}, option);
|
|
|
|
|
|
- return Page.generateQueryToListByStartWith(path, userData, option);
|
|
|
+ return Page.generateQueryToListByStartWith(path, userData, combinedOption);
|
|
|
};
|
|
|
|
|
|
/**
|
|
|
@@ -695,13 +688,22 @@ module.exports = function(crowi) {
|
|
|
*
|
|
|
* If `path` has `/` at the end, returns '{path}/*' and '{path}' self.
|
|
|
* If `path` doesn't have `/` at the end, returns '{path}*'
|
|
|
+ *
|
|
|
+ * *option*
|
|
|
+ * - includeDeletedPage -- if true, search deleted pages (default: false)
|
|
|
+ * - isRegExpEscapedFromPath -- if true, the regex strings included in `path` is escaped (default: false)
|
|
|
*/
|
|
|
pageSchema.statics.generateQueryToListByStartWith = function(path, userData, option) {
|
|
|
var Page = this;
|
|
|
var pathCondition = [];
|
|
|
var includeDeletedPage = option.includeDeletedPage || false;
|
|
|
+ var isRegExpEscapedFromPath = option.isRegExpEscapedFromPath || false;
|
|
|
|
|
|
- var queryReg = new RegExp('^' + path);
|
|
|
+ // var queryReg = new RegExp('^' + path);
|
|
|
+ var pattern = (isRegExpEscapedFromPath)
|
|
|
+ ? `^${escapeStringRegexp(path)}`
|
|
|
+ : `^${path}`;
|
|
|
+ var queryReg = new RegExp(pattern);
|
|
|
pathCondition.push({path: queryReg});
|
|
|
if (path.match(/\/$/)) {
|
|
|
debug('Page list by ending with /, so find also upper level page');
|