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

Merge pull request #886 from weseek/fix/871-path-contains-regex-symbols

Fix/871 path contains regex symbols
Haru 7 лет назад
Родитель
Сommit
7eb22fd773

+ 3 - 3
src/client/js/legacy/crowi.js

@@ -683,7 +683,7 @@ $(() => {
 window.addEventListener('load', (e) => {
 window.addEventListener('load', (e) => {
   // hash on page
   // hash on page
   if (location.hash) {
   if (location.hash) {
-    if (location.hash === '#edit' || location.hash === '#edit-form') {
+    if ((location.hash === '#edit' || location.hash === '#edit-form') && $('.tab-pane#edit').length > 0) {
       $('a[data-toggle="tab"][href="#edit"]').tab('show');
       $('a[data-toggle="tab"][href="#edit"]').tab('show');
       $('body').addClass('on-edit');
       $('body').addClass('on-edit');
       $('body').addClass('builtin-editor');
       $('body').addClass('builtin-editor');
@@ -691,12 +691,12 @@ window.addEventListener('load', (e) => {
       // focus
       // focus
       Crowi.setCaretLineAndFocusToEditor();
       Crowi.setCaretLineAndFocusToEditor();
     }
     }
-    else if (location.hash === '#hackmd') {
+    else if (location.hash === '#hackmd' && $('.tab-pane#hackmd').length > 0) {
       $('a[data-toggle="tab"][href="#hackmd"]').tab('show');
       $('a[data-toggle="tab"][href="#hackmd"]').tab('show');
       $('body').addClass('on-edit');
       $('body').addClass('on-edit');
       $('body').addClass('hackmd');
       $('body').addClass('hackmd');
     }
     }
-    else if (location.hash === '#revision-history') {
+    else if (location.hash === '#revision-history' && $('.tab-pane#revision-history').length > 0) {
       $('a[data-toggle="tab"][href="#revision-history"]').tab('show');
       $('a[data-toggle="tab"][href="#revision-history"]').tab('show');
     }
     }
   }
   }

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

@@ -188,7 +188,16 @@ class PageQueryBuilder {
       ? escapeStringRegexp(path) // escape
       ? escapeStringRegexp(path) // escape
       : pathSlashOmitted;
       : 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 });
     pathCondition.push({ path: queryReg });
 
 
     this.query = this.query
     this.query = this.query

+ 6 - 3
src/server/routes/page.js

@@ -253,7 +253,7 @@ module.exports = function(crowi, app) {
     addRendarVarsForScope(renderVars, page);
     addRendarVarsForScope(renderVars, page);
 
 
     await addRenderVarsForSlack(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)) {
     if (isUserPage(page.path)) {
       // change template
       // change template
@@ -406,7 +406,10 @@ module.exports = function(crowi, app) {
     let view;
     let view;
     const renderVars = { path };
     const renderVars = { path };
 
 
-    if (!isCreatable || req.isForbidden) {
+    if (!isCreatable) {
+      view = 'customlayout-selector/not_creatable';
+    }
+    else if (req.isForbidden) {
       view = 'customlayout-selector/forbidden';
       view = 'customlayout-selector/forbidden';
     }
     }
     else {
     else {
@@ -429,7 +432,7 @@ module.exports = function(crowi, app) {
 
 
     const limit = 50;
     const limit = 50;
     const offset = parseInt(req.query.offset) || 0;
     const offset = parseInt(req.query.offset) || 0;
-    await addRenderVarsForDescendants(renderVars, path, req.user, offset, limit);
+    await addRenderVarsForDescendants(renderVars, path, req.user, offset, limit, true);
 
 
     return res.render(view, renderVars);
     return res.render(view, renderVars);
   };
   };

+ 7 - 0
src/server/views/customlayout-selector/not_creatable.html

@@ -0,0 +1,7 @@
+{% if !layoutType() || 'crowi' === layoutType() %}
+  {% include '../layout-crowi/not_creatable.html' %}
+{% elseif !layoutType() || 'kibela' === layoutType()%}
+  {% include '../layout-kibela/not_creatable.html' %}
+{% else %}
+  {% include '../layout-growi/not_creatable.html' %}
+{% endif %}

+ 41 - 0
src/server/views/layout-crowi/not_creatable.html

@@ -0,0 +1,41 @@
+{% extends 'base/layout.html' %}
+
+{% block content_header %}
+
+  {% block content_header_before %}
+  {% endblock %}
+
+  <div class="header-wrap">
+    <header id="page-header">
+      <div>
+        <div>
+          <h1 class="title" id="revision-path"></h1>
+          <div id="revision-url" class="url-line"></div>
+        </div>
+      </div>
+
+    </header>
+  </div>
+
+  {% block content_header_after %}
+  {% endblock %}
+
+{% endblock %} {# /content_head #}
+
+
+{% block content_main_before %}
+  {% include '../widget/page_alerts.html' %}
+{% endblock %}
+
+
+{% block content_main %}
+  {% include '../widget/not_creatable_content.html' %}
+{% endblock %}
+
+
+{% block content_main_after %}
+{% endblock %}
+
+
+{% block content_footer %}
+{% endblock %}

+ 25 - 0
src/server/views/layout-growi/not_creatable.html

@@ -0,0 +1,25 @@
+{% extends 'base/layout.html' %}
+
+
+{% block content_header %}
+  {% include 'widget/header.html' with {isCreatable: false} %}
+{% endblock %}
+
+
+{% block content_main_before %}
+  {% include '../widget/page_alerts.html' %}
+{% endblock %}
+
+
+{% block content_main %}
+  <div class="row">
+    <div class="col-lg-10 col-md-9">
+      {% include '../widget/not_creatable_content.html' %}
+    </div> {# /.col- #}
+  </div>
+{% endblock %}
+
+{% block body_end %}
+  <div id="crowi-modals">
+  </div>
+{% endblock %}

+ 25 - 0
src/server/views/layout-kibela/not_creatable.html

@@ -0,0 +1,25 @@
+{% extends 'base/layout.html' %}
+
+
+{% block content_header %}
+  {% include 'widget/header.html' %}
+{% endblock %}
+
+
+{% block content_main_before %}
+  {% include '../widget/page_alerts.html' %}
+{% endblock %}
+
+
+{% block content_main %}
+  <div class="row">
+    <div class="bg-white round-corner">
+      {% include '../widget/not_creatable_content.html' %}
+    </div> {# /.col- #}
+  </div>
+{% endblock %}
+
+{% block body_end %}
+  <div id="crowi-modals">
+  </div>
+{% endblock %}

+ 36 - 0
src/server/views/widget/not_creatable_content.html

@@ -0,0 +1,36 @@
+<div class="row not-found-message-row m-b-20">
+  <div class="col-md-12">
+    <h2 class="text-muted">
+      <i class="icon-ban" aria-hidden="true"></i>
+      Couldn't create path
+    </h2>
+  </div>
+</div>
+
+<div id="content-main" class="content-main content-main-not-found page-list"
+  data-path="{{ path | preventXss }}"
+  data-current-user="{% if user %}{{ user._id.toString() }}{% endif %}"
+  >
+
+  <ul class="nav nav-tabs hidden-print">
+    <li class="nav-main-left-tab active">
+      <a href="#revision-body" data-toggle="tab">
+        <i class="icon-notebook"></i> List
+      </a>
+    </li>
+  </ul>
+
+  <div class="tab-content">
+    {# list view #}
+    <div class="p-t-10 active tab-pane page-list-container" id="revision-body">
+      {% if pages.length == 0 %}
+        <div class="m-t-10">
+          There are no pages under <strong>{{ path }}</strong>.
+        </div>
+      {% endif  %}
+
+      {% include '../widget/page_list.html' with { pages: pages, pager: pager, viewConfig: viewConfig } %}
+    </div>
+
+  </div>
+</div>