Skip Menu |
 

This queue is for tickets about the File-MMagic CPAN distribution.

Report information
The Basics
Id: 11121
Status: new
Priority: 0/
Queue: File-MMagic

People
Owner: Nobody in particular
Requestors: perl-bug [...] owl.me.uk
Cc:
AdminCc:

Bug Information
Severity: Normal
Broken in: 1.22
Fixed in: (no value)



Subject: Always returns application/octet-stream when $/ (RS) is undefined
Download (untitled) / with headers
text/plain 1.2k
perl v5.8.4, File::MMagic v1.22 I was having trouble with $mmagic->checktype_contents($image) returning 'application/octet-stream' in seemingly random situations. In the end, I discovered it was because I was doing the following: sub someSub { local $/ = undef; open F, $some_filename; my $image = <F>; close F; my $mimetype = $mmagic->checktype_contents($image); # ... etc } whereas the following code will set $mimetype correctly: sub someSub { my $image; { local $/ = undef; open F, $some_filename; $image = <F>; close F; } my $mimetype = $mmagic->checktype_contents($image); # ... etc } The problem stems back to the function readMagicEntry() in MMagic.pm, which contains two diamond (<FILEHANDLE>) operators, but doesn't localise $/ (input record separator) to its default value of "\n". I suspect (although I haven't tested it) adding the following line to the start of readMagicEntry() will fix the problem: local $/ = "\n"; I notice there is also a diamond in the checktype_filename() function, which will problem exhibit similar strangeness if used in a program with a non-default $/. I hope I've been helpful, and I'm sorry I don't have more time to test this thoroughly. ~ Rich Daley


This service is sponsored and maintained by Best Practical Solutions and runs on Perl.org infrastructure.

Please report any issues with rt.cpan.org to rt-cpan-admin@bestpractical.com.