diff --git a/incorporealcms/journal.py b/incorporealcms/journal.py index 833e29d..32296fb 100644 --- a/incorporealcms/journal.py +++ b/incorporealcms/journal.py @@ -4,7 +4,20 @@ from flask import Blueprint bp = Blueprint('journal_views', __name__, url_prefix='/') -@bp.route('/', defaults={'path': 'INDEX'}) +@bp.route('/', defaults={'path': 'index'}) @bp.route('/') def display_journal_entry(path): return path + + +def journal_file_resolver(path): + """Manipulate the request path to find appropriate journal files. + + * convert dir requests to index files + + Worth noting, Flask already does stuff like convert '/foo/../../../bar' to + '/bar', so we don't need to take care around file access here. + """ + if path.endswith('/'): + path = f'{path}index' + return path diff --git a/tests/test_journal.py b/tests/test_journal.py new file mode 100644 index 0000000..9fa1d12 --- /dev/null +++ b/tests/test_journal.py @@ -0,0 +1,14 @@ +"""Test journal views and helper methods.""" +from incorporealcms.journal import journal_file_resolver + + +def test_journal_file_resolver_dir_to_index(): + assert journal_file_resolver('/foo/') == '/foo/index' + + +def test_journal_file_resolver_subdir_to_index(): + assert journal_file_resolver('/foo/bar/') == '/foo/bar/index' + + +def test_journal_file_resolver_other_requests_fine(): + assert journal_file_resolver('/foo/baz') == '/foo/baz'