From f674b9e86ee609cef538168661f8719e8572ca13 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9gis=20Hanol?= Date: Fri, 19 Jan 2018 19:52:03 +0100 Subject: [PATCH] FIX: encode image filename so '[', ']' and '|' doesn't break the markdown --- app/assets/javascripts/discourse/lib/utilities.js.es6 | 6 +++--- test/javascripts/lib/utilities-test.js.es6 | 1 + 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/app/assets/javascripts/discourse/lib/utilities.js.es6 b/app/assets/javascripts/discourse/lib/utilities.js.es6 index ceeb8c81835..9d35e18fc9a 100644 --- a/app/assets/javascripts/discourse/lib/utilities.js.es6 +++ b/app/assets/javascripts/discourse/lib/utilities.js.es6 @@ -291,13 +291,13 @@ function isGUID(value) { function imageNameFromFileName(fileName) { const split = fileName.split('.'); - const name = split[split.length-2]; + let name = split[split.length - 2]; if (exports.isAppleDevice() && isGUID(name)) { - return I18n.t('upload_selector.default_image_alt_text'); + name = I18n.t('upload_selector.default_image_alt_text'); } - return name; + return encodeURIComponent(name); } export function allowsImages() { diff --git a/test/javascripts/lib/utilities-test.js.es6 b/test/javascripts/lib/utilities-test.js.es6 index 4a11b4bca9a..9b5f4e4265a 100644 --- a/test/javascripts/lib/utilities-test.js.es6 +++ b/test/javascripts/lib/utilities-test.js.es6 @@ -123,6 +123,7 @@ var testUploadMarkdown = function(filename) { QUnit.test("getUploadMarkdown", assert => { assert.equal(testUploadMarkdown("lolcat.gif"),'![lolcat|100x200](/uploads/123/abcdef.ext)'); + assert.equal(testUploadMarkdown("[foo|bar].png"),'![%5Bfoo%7Cbar%5D|100x200](/uploads/123/abcdef.ext)'); assert.ok(testUploadMarkdown("important.txt") === 'important.txt (42 Bytes)\n'); });