Explorar el Código

force to escape path if regular expression is invalid

Yuki Takei hace 7 años
padre
commit
10ef3abf5c
Se han modificado 2 ficheros con 11 adiciones y 2 borrados
  1. 10 1
      src/server/models/page.js
  2. 1 1
      src/server/routes/page.js

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

@@ -188,7 +188,16 @@ class PageQueryBuilder {
       ? escapeStringRegexp(path) // escape
       : pathSlashOmitted;
 
-    const queryReg = new RegExp(`^${pattern}`);
+    let queryReg;
+    try {
+      queryReg = new RegExp(`^${pattern}`);
+    }
+    // if regular expression is invalid
+    catch (e) {
+      // force to escape
+      queryReg = new RegExp(`^${escapeStringRegexp(pattern)}`);
+    }
+
     pathCondition.push({ path: queryReg });
 
     this.query = this.query

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

@@ -252,7 +252,7 @@ module.exports = function(crowi, app) {
     addRendarVarsForScope(renderVars, page);
 
     await addRenderVarsForSlack(renderVars, page);
-    await addRenderVarsForDescendants(renderVars, path, req.user, offset, limit);
+    await addRenderVarsForDescendants(renderVars, path, req.user, offset, limit, true);
 
     if (isUserPage(page.path)) {
       // change template