summaryrefslogtreecommitdiffstats
path: root/extensions/TypeSniffer/Extension.pm
diff options
context:
space:
mode:
authorByron Jones <bjones@mozilla.com>2012-06-14 15:32:53 +0200
committerByron Jones <bjones@mozilla.com>2012-06-14 15:32:53 +0200
commita38f6fe419a2d8cfd679b85f65c67a0cf67b4565 (patch)
tree04b0e3ed6b3400bbd83af48053ab487244a572e6 /extensions/TypeSniffer/Extension.pm
parent9b288d52c3b8ecdb932f7e0266e7c5bcedae4210 (diff)
downloadbugzilla-a38f6fe419a2d8cfd679b85f65c67a0cf67b4565.tar.gz
bugzilla-a38f6fe419a2d8cfd679b85f65c67a0cf67b4565.tar.xz
Update TypeSniffer to support 4.2
Diffstat (limited to 'extensions/TypeSniffer/Extension.pm')
-rw-r--r--extensions/TypeSniffer/Extension.pm24
1 files changed, 20 insertions, 4 deletions
diff --git a/extensions/TypeSniffer/Extension.pm b/extensions/TypeSniffer/Extension.pm
index 49488c9ad..bf9d9e856 100644
--- a/extensions/TypeSniffer/Extension.pm
+++ b/extensions/TypeSniffer/Extension.pm
@@ -43,12 +43,28 @@ sub attachment_process_data {
$params->{'contenttypemethod'} eq 'autodetect' &&
$attributes->{'mimetype'} eq 'application/octet-stream')
{
- # data is either a filehandle, or the data itself
- my $fh = ${$args->{'data'}};
+ # data attribute can be either scalar data or filehandle
+ # bugzilla.org/docs/3.6/en/html/api/Bugzilla/Attachment.html#create
+ my $fh = $attributes->{'data'};
if (!ref($fh)) {
- $fh = IO::Scalar->new(\$fh);
+ my $data = $attributes->{'data'};
+ $fh = new IO::Scalar \$data;
}
-
+ else {
+ # CGI.pm sends us an Fh that isn't actually an IO::Handle, but
+ # has a method for getting an actual handle out of it.
+ if (!$fh->isa('IO::Handle')) {
+ $fh = $fh->handle;
+ # ->handle returns an literal IO::Handle, even though the
+ # underlying object is a file. So we rebless it to be a proper
+ # IO::File object so that we can call ->seek on it and so on.
+ # Just in case CGI.pm fixes this some day, we check ->isa first.
+ if (!$fh->isa('IO::File')) {
+ bless $fh, 'IO::File';
+ }
+ }
+ }
+
my $mimetype = mimetype($fh);
if ($mimetype) {
$attributes->{'mimetype'} = $mimetype;