FIX: Fixed uploadPlaceholder regex failing on not escaped characters (#7442)

This commit is contained in:
Tim Lange
2019-04-29 04:32:48 +02:00
committed by Sam
parent 6449170e15
commit 574f39f9d0
2 changed files with 94 additions and 76 deletions

View File

@ -261,8 +261,9 @@ export default Ember.Component.extend({
// when adding two separate files with the same filename search for matching // when adding two separate files with the same filename search for matching
// placeholder already existing in the editor ie [Uploading: test.png...] // placeholder already existing in the editor ie [Uploading: test.png...]
// and add order nr to the next one: [Uplodading: test.png(1)...] // and add order nr to the next one: [Uplodading: test.png(1)...]
const escapedFilename = filename.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
const regexString = `\\[${I18n.t("uploading_filename", { const regexString = `\\[${I18n.t("uploading_filename", {
filename: filename + "(?:\\()?([0-9])?(?:\\))?" filename: escapedFilename + "(?:\\()?([0-9])?(?:\\))?"
})}\\]\\(\\)`; })}\\]\\(\\)`;
const globalRegex = new RegExp(regexString, "g"); const globalRegex = new RegExp(regexString, "g");
const matchingPlaceholder = this.get("composer.reply").match(globalRegex); const matchingPlaceholder = this.get("composer.reply").match(globalRegex);

View File

@ -101,81 +101,98 @@ QUnit.test("Tests the Composer controls", async assert => {
assert.ok(!exists(".bootbox.modal"), "the confirmation can be cancelled"); assert.ok(!exists(".bootbox.modal"), "the confirmation can be cancelled");
}); });
// Temporarily remove to see if this is breaking the test suite QUnit.test("Composer upload placeholder", async assert => {
// await visit("/");
// QUnit.test("Composer upload placeholder", async assert => { await click("#create-topic");
// await visit("/");
// await click("#create-topic"); const file1 = new Blob([""], { type: "image/png" });
// file1.name = "test.png";
// const file1 = new Blob([""], { type: "image/png" }); const data1 = {
// file1.name = "test.png"; files: [file1],
// const data1 = { result: {
// files: [file1], original_filename: "test.png",
// result: { thumbnail_width: 200,
// original_filename: "test.png", thumbnail_height: 300,
// thumbnail_width: 200, url: "/uploads/test1.ext"
// thumbnail_height: 300, }
// url: "/uploads/test1.ext" };
// }
// }; const file2 = new Blob([""], { type: "image/png" });
// file2.name = "test.png";
// const file2 = new Blob([""], { type: "image/png" }); const data2 = {
// file2.name = "test.png"; files: [file2],
// const data2 = { result: {
// files: [file2], original_filename: "test.png",
// result: { thumbnail_width: 100,
// original_filename: "test.png", thumbnail_height: 200,
// thumbnail_width: 100, url: "/uploads/test2.ext"
// thumbnail_height: 200, }
// url: "/uploads/test2.ext" };
// }
// }; const file3 = new Blob([""], { type: "image/png" });
// file3.name = "image.png";
// const file3 = new Blob([""], { type: "image/png" }); const data3 = {
// file3.name = "image.png"; files: [file3],
// const data3 = { result: {
// files: [file3], original_filename: "image.png",
// result: { thumbnail_width: 300,
// original_filename: "image.png", thumbnail_height: 400,
// thumbnail_width: 300, url: "/uploads/test3.ext"
// thumbnail_height: 400, }
// url: "/uploads/test3.ext" };
// }
// }; const file4 = new Blob([""], { type: "image/png" });
// file4.name = "ima++ge.png";
// await find(".wmd-controls").trigger("fileuploadsend", data1); const data4 = {
// assert.equal(find(".d-editor-input").val(), "[Uploading: test.png...]() "); files: [file4],
// result: {
// await find(".wmd-controls").trigger("fileuploadsend", data2); original_filename: "ima++ge.png",
// assert.equal( thumbnail_width: 300,
// find(".d-editor-input").val(), thumbnail_height: 400,
// "[Uploading: test.png...]() [Uploading: test.png(1)...]() " url: "/uploads/test3.ext"
// ); }
// };
// await find(".wmd-controls").trigger("fileuploadsend", data3);
// assert.equal( await find(".wmd-controls").trigger("fileuploadsend", data1);
// find(".d-editor-input").val(), assert.equal(find(".d-editor-input").val(), "[Uploading: test.png...]() ");
// "[Uploading: test.png...]() [Uploading: test.png(1)...]() [Uploading: image.png...]() "
// ); await find(".wmd-controls").trigger("fileuploadsend", data2);
// assert.equal(
// await find(".wmd-controls").trigger("fileuploaddone", data2); find(".d-editor-input").val(),
// assert.equal( "[Uploading: test.png...]() [Uploading: test.png(1)...]() "
// find(".d-editor-input").val(), );
// "[Uploading: test.png...]() ![test|100x200](/uploads/test2.ext) [Uploading: image.png...]() "
// ); await find(".wmd-controls").trigger("fileuploadsend", data4);
// assert.equal(
// await find(".wmd-controls").trigger("fileuploaddone", data3); find(".d-editor-input").val(),
// assert.equal( "[Uploading: test.png...]() [Uploading: test.png(1)...]() [Uploading: ima++ge.png...]() ",
// find(".d-editor-input").val(), "should accept files with unescaped characters"
// "[Uploading: test.png...]() ![test|100x200](/uploads/test2.ext) ![image|300x400](/uploads/test3.ext) " );
// );
// await find(".wmd-controls").trigger("fileuploadsend", data3);
// await find(".wmd-controls").trigger("fileuploaddone", data1); assert.equal(
// assert.equal( find(".d-editor-input").val(),
// find(".d-editor-input").val(), "[Uploading: test.png...]() [Uploading: test.png(1)...]() [Uploading: ima++ge.png...]() [Uploading: image.png...]() "
// "![test|200x300](/uploads/test1.ext) ![test|100x200](/uploads/test2.ext) ![image|300x400](/uploads/test3.ext) " );
// );
// }); await find(".wmd-controls").trigger("fileuploaddone", data2);
assert.equal(
find(".d-editor-input").val(),
"[Uploading: test.png...]() ![test|100x200](/uploads/test2.ext) [Uploading: ima++ge.png...]() [Uploading: image.png...]() "
);
await find(".wmd-controls").trigger("fileuploaddone", data3);
assert.equal(
find(".d-editor-input").val(),
"[Uploading: test.png...]() ![test|100x200](/uploads/test2.ext) [Uploading: ima++ge.png...]() ![image|300x400](/uploads/test3.ext) "
);
await find(".wmd-controls").trigger("fileuploaddone", data1);
assert.equal(
find(".d-editor-input").val(),
"![test|200x300](/uploads/test1.ext) ![test|100x200](/uploads/test2.ext) [Uploading: ima++ge.png...]() ![image|300x400](/uploads/test3.ext) "
);
});
QUnit.test("Create a topic with server side errors", async assert => { QUnit.test("Create a topic with server side errors", async assert => {
await visit("/"); await visit("/");