diff --git a/realms/__init__.py b/realms/__init__.py
index 59899cc..27b2ce7 100644
--- a/realms/__init__.py
+++ b/realms/__init__.py
@@ -5,6 +5,7 @@ reload(sys)
# noinspection PyUnresolvedReferences
sys.setdefaultencoding('utf-8')
+import base64
import time
import json
import httplib
@@ -185,6 +186,10 @@ def create_app(config=None):
def _jinja2_filter_datetime(ts):
return time.strftime('%b %d, %Y %I:%M %p', time.localtime(ts))
+ @app.template_filter('b64encode')
+ def _jinja2_filter_b64encode(s):
+ return base64.urlsafe_b64encode(s).rstrip("=")
+
@app.errorhandler(404)
def page_not_found(e):
return render_template('errors/404.html'), 404
diff --git a/realms/lib/util.py b/realms/lib/util.py
index 74dcf26..f25f314 100644
--- a/realms/lib/util.py
+++ b/realms/lib/util.py
@@ -83,9 +83,9 @@ def clean_url(url):
def to_canonical(s):
"""
- Double space -> single dash
- Double dash -> single dash
- Remove all non alphanumeric and dash except path separatos (/)
+ Remove leading/trailing whitespace
+ Remove leading underscores and backslashes "/"
+ Convert spaces to dashes "-"
Limit to first 128 chars
"""
reserved_chars = "&$+,:;=?@#"
@@ -95,7 +95,9 @@ def to_canonical(s):
s = str(s)
s = s.strip()
s = s.lstrip('_')
+ s = s.lstrip('/')
s = re.sub(r"\s", "-", s)
+ s = re.sub(r"/+", "/", s)
s = re.sub(r"[" + re.escape(reserved_chars) + "]", "", s)
s = re.sub(r"[" + re.escape(unsafe_chars) + "]", "", s)
s = s[:128]
diff --git a/realms/static/js/editor.js b/realms/static/js/editor.js
index 8097d17..6340f58 100644
--- a/realms/static/js/editor.js
+++ b/realms/static/js/editor.js
@@ -89,13 +89,13 @@ var aced = new Aced({
info: Commit.info,
submit: function(content) {
var data = {
- name: $page_name.val(),
+ name: $page_name.val().replace(/^\/*/g, "").replace(/\/+/g, "/"),
message: $page_message.val(),
content: content
};
// If renaming an existing page, use the old page name for the URL to PUT to
- var subPath = (PAGE_NAME) ? PAGE_NAME : data['name']
+ var subPath = (PAGE_NAME) ? PAGE_NAME : data['name'];
var path = Config['RELATIVE_PATH'] + '/' + subPath;
var newPath = Config['RELATIVE_PATH'] + '/' + data['name'];
diff --git a/realms/templates/wiki/edit.html b/realms/templates/wiki/edit.html
index 2647359..e43bd8d 100644
--- a/realms/templates/wiki/edit.html
+++ b/realms/templates/wiki/edit.html
@@ -155,7 +155,7 @@
What is Markdown?