fix some issues with path names

This commit is contained in:
Matthew Scragg 2015-12-09 17:41:15 -06:00
parent 7d9cc29223
commit 93df0e081a
4 changed files with 13 additions and 6 deletions

View file

@ -5,6 +5,7 @@ reload(sys)
# noinspection PyUnresolvedReferences # noinspection PyUnresolvedReferences
sys.setdefaultencoding('utf-8') sys.setdefaultencoding('utf-8')
import base64
import time import time
import json import json
import httplib import httplib
@ -185,6 +186,10 @@ def create_app(config=None):
def _jinja2_filter_datetime(ts): def _jinja2_filter_datetime(ts):
return time.strftime('%b %d, %Y %I:%M %p', time.localtime(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) @app.errorhandler(404)
def page_not_found(e): def page_not_found(e):
return render_template('errors/404.html'), 404 return render_template('errors/404.html'), 404

View file

@ -83,9 +83,9 @@ def clean_url(url):
def to_canonical(s): def to_canonical(s):
""" """
Double space -> single dash Remove leading/trailing whitespace
Double dash -> single dash Remove leading underscores and backslashes "/"
Remove all non alphanumeric and dash except path separatos (/) Convert spaces to dashes "-"
Limit to first 128 chars Limit to first 128 chars
""" """
reserved_chars = "&$+,:;=?@#" reserved_chars = "&$+,:;=?@#"
@ -95,7 +95,9 @@ def to_canonical(s):
s = str(s) s = str(s)
s = s.strip() s = s.strip()
s = s.lstrip('_') s = s.lstrip('_')
s = s.lstrip('/')
s = re.sub(r"\s", "-", s) 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(reserved_chars) + "]", "", s)
s = re.sub(r"[" + re.escape(unsafe_chars) + "]", "", s) s = re.sub(r"[" + re.escape(unsafe_chars) + "]", "", s)
s = s[:128] s = s[:128]

View file

@ -89,13 +89,13 @@ var aced = new Aced({
info: Commit.info, info: Commit.info,
submit: function(content) { submit: function(content) {
var data = { var data = {
name: $page_name.val(), name: $page_name.val().replace(/^\/*/g, "").replace(/\/+/g, "/"),
message: $page_message.val(), message: $page_message.val(),
content: content content: content
}; };
// If renaming an existing page, use the old page name for the URL to PUT to // 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 path = Config['RELATIVE_PATH'] + '/' + subPath;
var newPath = Config['RELATIVE_PATH'] + '/' + data['name']; var newPath = Config['RELATIVE_PATH'] + '/' + data['name'];

View file

@ -155,7 +155,7 @@
<a class="markdown-help" href=""><span class="hidden">What is Markdown?</span></a> <a class="markdown-help" href=""><span class="hidden">What is Markdown?</span></a>
</header> </header>
<section id="entry-markdown-content" class="entry-markdown-content"> <section id="entry-markdown-content" class="entry-markdown-content">
<div id="editor-{{ name }}" data-submitbtn='submit-btn' data-themeselect="theme-list" data-mode="markdown" <div id="editor-{{ name | b64encode }}" data-submitbtn='submit-btn' data-themeselect="theme-list" data-mode="markdown"
data-preview="preview" class="editor">{{ content }}</div> data-preview="preview" class="editor">{{ content }}</div>
</section> </section>
</section> </section>