From a66a71bc45f176c549f227ee843875f23b71e5e4 Mon Sep 17 00:00:00 2001 From: Mischa POSLAWSKY Date: Mon, 28 Oct 2019 03:36:22 +0100 Subject: [PATCH] edit/page: keep page named after existing directory Allow either subdir.html or subdir/index.html, preventing edit from creating conforming duplicates. Reported-by: Arie van Marion --- edit/page.js | 2 +- edit/page/index.php | 5 ++++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/edit/page.js b/edit/page.js index 522d63e..9997e29 100644 --- a/edit/page.js +++ b/edit/page.js @@ -2,7 +2,7 @@ CKEDITOR.plugins.add('inlinesave', { init: function(editor) { editor.addCommand( 'inlinesave', { exec: function (editor) { - var pagename = window.location.pathname.replace(/\/$/, '/index'); + var pagename = window.location.pathname; var body = editor.getData(); // empty line is equivalent to a paragraph break body = body.replace(/
\s*
/g, '

'); diff --git a/edit/page/index.php b/edit/page/index.php index 086c753..48f8942 100644 --- a/edit/page/index.php +++ b/edit/page/index.php @@ -45,9 +45,12 @@ if (!$_POST) if (!$Args) abort("geen bestand aangeleverd", '409 input error'); -$filename = ltrim($Args, '/').'.html'; +$filename = trim($Args, '/'); if (preg_match('{^\.}', $filename)) abort("ongeldige bestandsnaam: $filename", '403 input error'); +if (is_dir($filename) && !file_exists("$filename.html")) + $filename .= '/index'; +$filename .= '.html'; if (file_exists($filename) and !is_writable($filename)) abort("onwijzigbaar bestand: $filename", '403 input error'); -- 2.30.0