Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
bugzilla
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
etersoft
bugzilla
Commits
1b0d2440
Commit
1b0d2440
authored
Jul 04, 2012
by
Matt Selsky
Committed by
Frédéric Buclin
Jul 04, 2012
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Bug 760562: Integrate TypeSniffer into core codebase (auto-detect attachment MIME type)
r/a=LpSolit
parent
08f32ca1
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
61 additions
and
7 deletions
+61
-7
Attachment.pm
Bugzilla/Attachment.pm
+46
-7
Requirements.pm
Bugzilla/Install/Requirements.pm
+14
-0
strings.txt.pl
template/en/default/setup/strings.txt.pl
+1
-0
No files found.
Bugzilla/Attachment.pm
View file @
1b0d2440
...
...
@@ -513,6 +513,52 @@ sub _check_content_type {
}
trick_taint
(
$content_type
);
# $ENV{HOME} must be defined when using File::MimeInfo::Magic,
# see https://rt.cpan.org/Public/Bug/Display.html?id=41744.
local
$ENV
{
HOME
}
=
$ENV
{
HOME
}
||
File::
Spec
->
rootdir
();
# If we have autodetected application/octet-stream from the Content-Type
# header, let's have a better go using a sniffer if available.
if
(
defined
Bugzilla
->
input_params
->
{
contenttypemethod
}
&&
Bugzilla
->
input_params
->
{
contenttypemethod
}
eq
'autodetect'
&&
$content_type
eq
'application/octet-stream'
&&
Bugzilla
->
feature
(
'typesniffer'
))
{
import
File::MimeInfo::
Magic
qw(mimetype)
;
require
IO::
Scalar
;
# data is either a filehandle, or the data itself.
my
$fh
=
$params
->
{
data
};
if
(
!
ref
(
$fh
))
{
$fh
=
new
IO::
Scalar
\
$fh
;
}
elsif
(
!
$fh
->
isa
(
'IO::Handle'
))
{
# 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.
$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
);
$content_type
=
$mimetype
if
$mimetype
;
}
# Make sure patches are viewable in the browser
if
(
!
ref
(
$invocant
)
&&
defined
Bugzilla
->
input_params
->
{
contenttypemethod
}
&&
Bugzilla
->
input_params
->
{
contenttypemethod
}
eq
'autodetect'
&&
$content_type
=~
m{text/x-(?:diff|patch)}
)
{
$params
->
{
ispatch
}
=
1
;
$content_type
=
'text/plain'
;
}
return
$content_type
;
}
...
...
@@ -926,13 +972,6 @@ sub get_content_type {
$cgi
->
uploadInfo
(
$cgi
->
param
(
'data'
))
->
{
'Content-Type'
};
$content_type
||
ThrowUserError
(
"missing_content_type"
);
# Set the ispatch flag to 1 if the content type
# is text/x-diff or text/x-patch
if
(
$content_type
=~
m{text/x-(?:diff|patch)}
)
{
$cgi
->
param
(
'ispatch'
,
1
);
$content_type
=
'text/plain'
;
}
# Internet Explorer sends image/x-png for PNG images,
# so convert that to image/png to match other browsers.
if
(
$content_type
eq
'image/x-png'
)
{
...
...
Bugzilla/Install/Requirements.pm
View file @
1b0d2440
...
...
@@ -360,6 +360,20 @@ sub OPTIONAL_MODULES {
version
=>
'0.96'
,
feature
=>
[
'mod_perl'
],
},
# typesniffer
{
package
=>
'File-MimeInfo'
,
module
=>
'File::MimeInfo::Magic'
,
version
=>
'0'
,
feature
=>
[
'typesniffer'
],
},
{
package
=>
'IO-stringy'
,
module
=>
'IO::Scalar'
,
version
=>
'0'
,
feature
=>
[
'typesniffer'
],
},
);
my
$extra_modules
=
_get_extension_requirements
(
'OPTIONAL_MODULES'
);
...
...
template/en/default/setup/strings.txt.pl
View file @
1b0d2440
...
...
@@ -99,6 +99,7 @@ END
feature_updates
=>
'Automatic Update Notifications'
,
feature_xmlrpc
=>
'XML-RPC Interface'
,
feature_detect_charset
=>
'Automatic charset detection for text attachments'
,
feature_typesniffer
=>
'Sniff MIME type of attachments'
,
file_remove
=>
'Removing ##name##...'
,
file_rename
=>
'Renaming ##from## to ##to##...'
,
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment