Browse Source

Merge pull request #154 from weseek/fix/153-problem-with-round-bracket

Fix/153 problem with round bracket
Yuki Takei 8 years ago
parent
commit
3d05a318f5
2 changed files with 10 additions and 3 deletions
  1. 1 1
      CHANGES.md
  2. 9 2
      lib/models/page.js

+ 1 - 1
CHANGES.md

@@ -3,7 +3,7 @@ CHANGES
 
 ## 2.0.8
 
-* 
+* Fix: The problem that path including round bracket makes something bad
 
 ## 2.0.7
 

+ 9 - 2
lib/models/page.js

@@ -661,7 +661,7 @@ module.exports = function(crowi) {
     var pathCondition = [];
     var includeDeletedPage = option.includeDeletedPage || false;
 
-    var queryReg = new RegExp('^' + path);
+    var queryReg = new RegExp('^' + escapeRoundBrackets(path));
     pathCondition.push({path: queryReg});
     if (path.match(/\/$/)) {
       debug('Page list by ending with /, so find also upper level page');
@@ -1090,7 +1090,7 @@ module.exports = function(crowi) {
   pageSchema.statics.renameRecursively = function(pageData, newPagePathPrefix, user, options) {
     var Page = this
       , path = pageData.path
-      , pathRegExp = new RegExp('^' + path, 'i');
+      , pathRegExp = new RegExp('^' + escapeRoundBrackets(path), 'i');
 
     return new Promise(function(resolve, reject) {
       Page
@@ -1113,6 +1113,13 @@ module.exports = function(crowi) {
     return;
   };
 
+  function escapeRoundBrackets(path) {
+    // replace
+    //   '(' -> '\('
+    //   ')' -> '\)'
+    return path.replace(/(\(|\))/g, '\\$1');
+  }
+
   pageSchema.statics.GRANT_PUBLIC = GRANT_PUBLIC;
   pageSchema.statics.GRANT_RESTRICTED = GRANT_RESTRICTED;
   pageSchema.statics.GRANT_SPECIFIED = GRANT_SPECIFIED;