mirror of
https://github.com/codeninjasllc/discourse.git
synced 2024-11-23 15:48:43 -05:00
FIX: can no longer paste image in Chrome post editor
This commit is contained in:
parent
44cd5505d3
commit
5a56af03bc
5 changed files with 25 additions and 5 deletions
|
@ -172,6 +172,8 @@ Discourse.Utilities = {
|
|||
return false;
|
||||
} else if (files.length > 0) {
|
||||
var upload = files[0];
|
||||
// if the image was pasted, sets its name to a default one
|
||||
if (upload instanceof Blob && !(upload instanceof File) && upload.type === "image/png") { upload.name = "blob.png"; }
|
||||
// check that the uploaded file is authorized
|
||||
if (!Discourse.Utilities.isAuthorizedUpload(upload)) {
|
||||
var extensions = Discourse.SiteSettings.authorized_extensions.replace(/\|/g, ", ");
|
||||
|
|
|
@ -154,7 +154,7 @@ class CookedPostProcessor
|
|||
|
||||
def get_filename(upload, src)
|
||||
return File.basename(src) unless upload
|
||||
return upload.original_filename unless upload.original_filename == "blob"
|
||||
return upload.original_filename unless upload.original_filename =~ /^blob(\.png)?$/i
|
||||
return I18n.t('upload.pasted_image_filename')
|
||||
end
|
||||
|
||||
|
|
|
@ -230,7 +230,7 @@ describe CookedPostProcessor do
|
|||
end
|
||||
|
||||
it "returns a generic name for pasted images" do
|
||||
upload = Fabricate.build(:upload, { original_filename: "blob" })
|
||||
upload = Fabricate.build(:upload, { original_filename: "blob.png" })
|
||||
cpp.get_filename(upload, "http://domain.com/image.png").should == I18n.t('upload.pasted_image_filename')
|
||||
end
|
||||
|
||||
|
|
|
@ -41,12 +41,28 @@ test("prevents files that are too big from being uploaded", function() {
|
|||
ok(bootbox.alert.calledWith(Em.String.i18n('post.errors.upload_too_large', { max_size_kb: 5 })));
|
||||
});
|
||||
|
||||
var dummyBlob = function() {
|
||||
window.BlobBuilder = window.BlobBuilder || window.WebKitBlobBuilder || window.MozBlobBuilder || window.MSBlobBuilder;
|
||||
if (window.BlobBuilder) {
|
||||
var bb = new window.BlobBuilder();
|
||||
bb.append([1]);
|
||||
return bb.getBlob("image/png");
|
||||
} else {
|
||||
return new Blob([1], { "type" : "image\/png" });
|
||||
}
|
||||
};
|
||||
|
||||
test("allows valid uploads to go through", function() {
|
||||
var image = { name: "image.png", size: 10 * 1024 };
|
||||
Discourse.SiteSettings.max_upload_size_kb = 15;
|
||||
this.stub(bootbox, "alert");
|
||||
|
||||
// image
|
||||
var image = { name: "image.png", size: 10 * 1024 };
|
||||
ok(validUpload([image]));
|
||||
// pasted image
|
||||
var pastedImage = dummyBlob();
|
||||
ok(validUpload([pastedImage]));
|
||||
|
||||
ok(!bootbox.alert.calledOnce);
|
||||
});
|
||||
|
||||
|
|
|
@ -125,7 +125,9 @@ var jsHintOpts = {
|
|||
"controllerFor",
|
||||
"containsInstance",
|
||||
"deepEqual",
|
||||
"resolvingPromiseWith"],
|
||||
"resolvingPromiseWith",
|
||||
"Blob",
|
||||
"File"],
|
||||
"node" : false,
|
||||
"browser" : true,
|
||||
"boss" : true,
|
||||
|
@ -183,4 +185,4 @@ var jsHintOpts = {
|
|||
/external_development\//,
|
||||
/external_production\//,
|
||||
/defer\//,
|
||||
/locales\//]) %>
|
||||
/locales\//]) %>
|
||||
|
|
Loading…
Reference in a new issue