fix some issues with path names
This commit is contained in:
parent
7d9cc29223
commit
93df0e081a
|
@ -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
|
||||
|
|
|
@ -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]
|
||||
|
|
|
@ -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'];
|
||||
|
||||
|
|
|
@ -155,7 +155,7 @@
|
|||
<a class="markdown-help" href=""><span class="hidden">What is Markdown?</span></a>
|
||||
</header>
|
||||
<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>
|
||||
</section>
|
||||
</section>
|
||||
|
|
Loading…
Reference in a new issue