Просмотр исходного кода

Redirect if the page path is invalid

Sotaro KARASAWA 9 лет назад
Родитель
Сommit
af160629ab
2 измененных файлов с 13 добавлено и 1 удалено
  1. 6 0
      lib/models/page.js
  2. 7 1
      lib/routes/page.js

+ 6 - 0
lib/models/page.js

@@ -400,6 +400,12 @@ module.exports = function(crowi) {
     return isCreatable;
   };
 
+  pageSchema.statics.fixToCreatableName = function(path) {
+    return path
+      .replace(/\/\//g, '/')
+      ;
+  };
+
   pageSchema.statics.updateRevision = function(pageId, revisionId, cb) {
     this.update({_id: pageId}, {revision: revisionId}, {}, function(err, data) {
       cb(err, data);

+ 7 - 1
lib/routes/page.js

@@ -307,7 +307,6 @@ module.exports = function(crowi, app) {
         res.redirect('/');
         return ;
       }
-
       if (req.query.revision) {
         return res.redirect(encodeURI(path));
       }
@@ -321,6 +320,13 @@ module.exports = function(crowi, app) {
         if (page) {
           return res.redirect(encodeURI(path) + '/');
         } else {
+
+          var fixed = Page.fixToCreatableName(path)
+          if (fixed !== path) {
+            res.redirect(fixed);
+            return ;
+          }
+
           debug('Catch pageShow', err);
           return renderPage(null, req, res);
         }