Don't allow trailing slashes on catchall routes
This commit is contained in:
parent
45eec97bf3
commit
b0a5a53b09
|
@ -2,7 +2,8 @@
|
||||||
|
|
||||||
"""Flask app for Rophako."""
|
"""Flask app for Rophako."""
|
||||||
|
|
||||||
from flask import Flask, g, request, session, render_template, send_file, abort
|
from flask import (Flask, g, request, session, render_template, send_file,
|
||||||
|
abort, redirect)
|
||||||
from flask_sslify import SSLify
|
from flask_sslify import SSLify
|
||||||
import jinja2
|
import jinja2
|
||||||
import os.path
|
import os.path
|
||||||
|
@ -128,6 +129,10 @@ def catchall(path):
|
||||||
"""The catch-all path handler. If it exists in the www folders, it's sent,
|
"""The catch-all path handler. If it exists in the www folders, it's sent,
|
||||||
otherwise we give the 404 error page."""
|
otherwise we give the 404 error page."""
|
||||||
|
|
||||||
|
if path.endswith("/"):
|
||||||
|
path = path.strip("/") # Remove trailing slashes.
|
||||||
|
return redirect(path)
|
||||||
|
|
||||||
# Search for this file.
|
# Search for this file.
|
||||||
for root in [Config.site.site_root, "rophako/www"]:
|
for root in [Config.site.site_root, "rophako/www"]:
|
||||||
abspath = os.path.abspath("{}/{}".format(root, path))
|
abspath = os.path.abspath("{}/{}".format(root, path))
|
||||||
|
|
Loading…
Reference in New Issue
Block a user