From: Mischa POSLAWSKY Date: Mon, 28 Oct 2019 02:36:22 +0000 (+0100) Subject: edit/page: keep page named after existing directory X-Git-Tag: v4.1~4 X-Git-Url: http://git.shiar.nl/minimedit.git/commitdiff_plain/a66a71bc45f176c549f227ee843875f23b71e5e4 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 --- 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');