Commit 7306fabd authored by NGPixel's avatar NGPixel

fix: auto-trim trailing slash from paths + illegal chars check during move

parent 566043ec
...@@ -214,10 +214,15 @@ module.exports = class Page extends Model { ...@@ -214,10 +214,15 @@ module.exports = class Page extends Model {
*/ */
static async createPage(opts) { static async createPage(opts) {
// -> Validate path // -> Validate path
if (opts.path.indexOf('.') >= 0 || opts.path.indexOf(' ') >= 0) { if (opts.path.indexOf('.') >= 0 || opts.path.indexOf(' ') >= 0 || opts.path.index('\\') >= 0) {
throw new WIKI.Error.PageIllegalPath() throw new WIKI.Error.PageIllegalPath()
} }
// -> Remove trailing slash
if (opts.path.endsWidth('/')) {
opts.path = opts.path.slice(0, -1)
}
// -> Check for page access // -> Check for page access
if (!WIKI.auth.checkAccess(opts.user, ['write:pages'], { if (!WIKI.auth.checkAccess(opts.user, ['write:pages'], {
locale: opts.locale, locale: opts.locale,
...@@ -398,6 +403,16 @@ module.exports = class Page extends Model { ...@@ -398,6 +403,16 @@ module.exports = class Page extends Model {
throw new WIKI.Error.PageNotFound() throw new WIKI.Error.PageNotFound()
} }
// -> Validate path
if (opts.destinationPath.indexOf('.') >= 0 || opts.destinationPath.indexOf(' ') >= 0 || opts.destinationPath.index('\\') >= 0) {
throw new WIKI.Error.PageIllegalPath()
}
// -> Remove trailing slash
if (opts.destinationPath.endsWidth('/')) {
opts.destinationPath = opts.destinationPath.slice(0, -1)
}
// -> Check for source page access // -> Check for source page access
if (!WIKI.auth.checkAccess(opts.user, ['manage:pages'], { if (!WIKI.auth.checkAccess(opts.user, ['manage:pages'], {
locale: page.localeCode, locale: page.localeCode,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment