summaryrefslogtreecommitdiffstats
path: root/post_bug.cgi
diff options
context:
space:
mode:
authorKohei Yoshino <kohei.yoshino@gmail.com>2018-08-10 14:56:19 +0200
committerDylan William Hardison <dylan@hardison.net>2018-08-10 14:56:19 +0200
commit5a43b27f7940be9697f312c550fa2de11a9e14d7 (patch)
tree9e6e91abf14d1052366b8815b0fa63f4a0655372 /post_bug.cgi
parent1f35e100eaab5776633a3b995f3c32a0438f6e86 (diff)
downloadbugzilla-5a43b27f7940be9697f312c550fa2de11a9e14d7.tar.gz
bugzilla-5a43b27f7940be9697f312c550fa2de11a9e14d7.tar.xz
Bug 602313 - Allow creation of attachments by pasting an image from clipboard, as well as by drag-and-dropping a file from desktop
Diffstat (limited to 'post_bug.cgi')
-rwxr-xr-xpost_bug.cgi24
1 files changed, 21 insertions, 3 deletions
diff --git a/post_bug.cgi b/post_bug.cgi
index e9a3ed1de..2fd27ea86 100755
--- a/post_bug.cgi
+++ b/post_bug.cgi
@@ -29,6 +29,7 @@ use Bugzilla::Token;
use Bugzilla::Flag;
use List::MoreUtils qw(uniq);
+use MIME::Base64 qw(decode_base64);
my $user = Bugzilla->login(LOGIN_REQUIRED);
@@ -174,13 +175,30 @@ if (defined $cgi->param('version')) {
# Add an attachment if requested.
my $data_fh = $cgi->upload('data');
my $attach_text = $cgi->param('attach_text');
+my $data_base64 = $cgi->param('data_base64');
-if ($data_fh || $attach_text) {
+if ($data_fh || $attach_text || $data_base64) {
$cgi->param('isprivate', $cgi->param('comment_is_private'));
# Must be called before create() as it may alter $cgi->param('ispatch').
my $content_type = Bugzilla::Attachment::get_content_type();
my $attachment;
+ my $data;
+ my $filename;
+
+ if ($attach_text) {
+ # Convert to unix line-endings if pasting a patch
+ if (scalar($cgi->param('ispatch'))) {
+ $attach_text =~ s/[\012\015]{1,2}/\012/g;
+ }
+ $data = $attach_text;
+ $filename = "file_$id.txt";
+ } elsif ($data_base64) {
+ $data = decode_base64($data_base64);
+ $filename = $cgi->param('filename') || "file_$id";
+ } else {
+ $data = $filename = $data_fh;
+ }
# If the attachment cannot be successfully added to the bug,
# we notify the user, but we don't interrupt the bug creation process.
@@ -190,9 +208,9 @@ if ($data_fh || $attach_text) {
$attachment = Bugzilla::Attachment->create(
{bug => $bug,
creation_ts => $timestamp,
- data => $attach_text || $data_fh,
+ data => $data,
description => scalar $cgi->param('description'),
- filename => $attach_text ? "file_$id.txt" : $data_fh,
+ filename => $filename,
ispatch => scalar $cgi->param('ispatch'),
isprivate => scalar $cgi->param('isprivate'),
mimetype => $content_type,