markov2 / perl5-MIME-Types

Definition of MIME types
http://perl.overmeer.net/CPAN
4 stars 1 forks source link

2.16 release now returns strange types like 'image/vnd.mozilla.apng', breaks downstreams #1

Closed vanstyn closed 6 years ago

vanstyn commented 6 years ago

The recent 2.16 release breaks downstream Email::MIME::CreateHTML. If you look at the tests in that distribution which now fail, you can see that files which are expected to be 'image/png' are now being reported as strange values like 'image/vnd.mozilla.apng'

I see that there were changes to the IANA parsing in this release. Perhaps the bug is that now alias MIME types are now being returned instead of the primary type? Just a guess since that looks like a "vendor" specific type

markov2 commented 6 years ago

I can install your Email::MIME::CreateHTML without error.

Can you please be a bit more specific how to repeat the issue? The type table looks correct to me.

I see that there were changes to the IANA parsing in this release. Perhaps the bug is that now alias MIME types are now being returned instead of the primary type? Just a guess since that looks like a "vendor" specific type

Well, png is a valid type for 'image/vnd.mozilla.apng' so there certainly is a relation.

Can you reproduce the error for me? Small example script or at least tell me which function you use and how? -- Regards, MarkOv


   Mark Overmeer MSc                                MARKOV Solutions
   Mark@Overmeer.net                          solutions@overmeer.net

http://Mark.Overmeer.net http://solutions.overmeer.net

vanstyn commented 6 years ago

In all locations I've tested it so far (perlbrew, system perls, docker) I get the same failures when MIME::Types 2.16 is installed, but not when 2.14 is installed. I just tried again and got the same result.

If you have access to docker, here is an easy way to reproduce:

docker run --rm -it perl:5.26 bash # gives a shell on a fresh, temp virtual system
cpanm -v Email::MIME::CreateHTML # will pull MIME::Types 2.16, and fail

# manually install MIME::Types 2.14
cpanm http://cpan.metacpan.org/authors/id/M/MA/MARKOV/MIME-Types-2.14.tar.gz

# Now it works:
cpanm -v Email::MIME::CreateHTML

Here is the failing test output you should see:

t/Email-MIME-CreateHTML-Resolver.t .. 
1..14
ok 1 (Compiled Email::MIME::CreateHTML::Resolver version 1.041)
ok 2 (HTTP URL)
ok 3 (HTTPS URL)
ok 4 (FTP URL)
ok 5 (absolute filepath)
ok 6 (relative filepath)
ok 7 (UNC filepath)
ok 8 (windows-style filepath)
ok 9 (file URL)
ok 10 (Custom resolver)
ok 11 (No URI)
ok 12 (Resolver not an object)
ok 13 (Resolver doesn't have get_resource method)
ok 14 (Dodgy object cache)
ok
t/Email-MIME-CreateHTML.t ........... 
1..49
ok 1 (compiled version 1.041)
ok 2 (------ HTML, no embedded objects, no text alternative - Email::MIME object returned)
ok 3 (content-type: text/html; charset="UTF-8")
ok 4 (body)
ok 5 (------ HTML, no embedded objects, with text alternative - Email::MIME object returned)
ok 6 (content-type: multipart/alternative; boundary="1516933029.A8A30.16355")
ok 7 (number of parts)
ok 8 (content-type: text/plain)
ok 9 (body)
ok 10 (content-type: text/html; charset="UTF-8")
ok 11 (body)
ok 12 (------ HTML with embedded objects, no text alternative - Email::MIME object returned)
ok 13 (content-type: multipart/related; boundary="1516933029.BfED5C1.16355")
ok 14 (number of parts)
ok 15 (content-type: text/html; charset="UTF-8")
ok 16 (body)
not ok 17 at line 107 in t/Email-MIME-CreateHTML.t (Mime types image/png and image/jpeg)
ok 18 (------ HTML with embedded objects, with text alternative - Email::MIME object returned)
ok 19 (content-type: multipart/alternative; boundary="1516933029.A225a9.16355")
ok 20 (number of parts)
ok 21 (content-type: text/plain)
ok 22 (body)
ok 23 (content-type: multipart/related; boundary="1516933029.dbEcf5.16355")
ok 24 (number of parts)
ok 25 (content-type: text/html; charset="UTF-8")
ok 26 (body)
not ok 27 at line 149 in t/Email-MIME-CreateHTML.t (MIME type image/png present)
ok 28 (MIME type image/jpeg present)
ok 29 (------ HTML with embedded objects, no text alternative - Email::MIME object returned)
ok 30 (content-type: multipart/related; boundary="1516933029.C148110.16355")
ok 31 (number of parts)
ok 32 (content-type: text/html; charset="ISO-8859-1")
ok 33 (body)
ok 34 (content-type: image/jpeg; name="landscape.jpg")
ok 35 (------ Caching : Image files in place)
ok 36 (Bad object_cache caught)
ok 37 (mime object created)
ok 38 (number of parts)
ok 39 (content-type: text/html; charset="UTF-8")
ok 40 (body)
not ok 41 at line 267 in t/Email-MIME-CreateHTML.t (content-type: image/vnd.mozilla.apng; name="cache_test_end.png")
ok 42 (content-type: image/jpeg; name="cache_test_landscape.jpg")
ok 43 (Image files removed)
ok 44 (mime object created (second mail))
ok 45 (number of parts)
ok 46 (content-type: text/html; charset="UTF-8")
ok 47 (body)
not ok 48 at line 267 in t/Email-MIME-CreateHTML.t (content-type: image/vnd.mozilla.apng; name="cache_test_end.png")
ok 49 (content-type: image/jpeg; name="cache_test_landscape.jpg")
Failed 4/49 subtests 
t/UTF-8_html.t ...................... 
ok 1
ok 2
ok 3
ok 4
1..4
ok
t/pod.t ............................. 
1..5
ok 1 - POD test for lib/Email/MIME/CreateHTML.pm
ok 2 - POD test for lib/Email/MIME/CreateHTML/Resolver.pm
ok 3 - POD test for lib/Email/MIME/CreateHTML/Resolver/LWP.pm
ok 4 - POD test for lib/Email/MIME/CreateHTML/Resolver/Cached.pm
ok 5 - POD test for lib/Email/MIME/CreateHTML/Resolver/Filesystem.pm
ok
t/pod_coverage.t .................... 
1..5
ok 1 - Pod coverage on Email::MIME::CreateHTML
ok 2 - Pod coverage on Email::MIME::CreateHTML::Resolver
ok 3 - Pod coverage on Email::MIME::CreateHTML::Resolver::LWP
ok 4 - Pod coverage on Email::MIME::CreateHTML::Resolver::Cached
ok 5 - Pod coverage on Email::MIME::CreateHTML::Resolver::Filesystem
ok

Test Summary Report
-------------------
t/Email-MIME-CreateHTML.t         (Wstat: 0 Tests: 49 Failed: 4)
  Failed tests:  17, 27, 41, 48
Files=5, Tests=77,  1 wallclock secs ( 0.05 usr  0.00 sys +  0.94 cusr  0.06 csys =  1.05 CPU)
Result: FAIL
markov2 commented 6 years ago

My test yesterday used an incorrect path.

You gave a long answer for a simple test: perl -Ilib -MMIME::Types -we 'print MIME::Types::by_suffix("a.png"), "\n"'

(You do not want to the OO interface of the module?)

Anyways... it is quite hard to pick the most optimal mime-type for an extension automatically. The data (even IANA) is not always clear about that.

I have changed the logic a bit, and now we get the right answer. Releases as 2.17. -- Thanks for complaining ;-)

           MarkOv

   Mark Overmeer MSc                                MARKOV Solutions
   Mark@Overmeer.net                          solutions@overmeer.net

http://Mark.Overmeer.net http://solutions.overmeer.net

vanstyn commented 6 years ago

Thanks for your help. I actually didn't write Email::MIME::CreateHTML, or any of the code which interacts with your module, and I'm not even that familiar with its design. I'm just the current maintainer, which happened because it was abandoned. It was one of my deps and it stopped working when perl 5.18 was released and so I had to take it over to get it fixed. That's why I didn't have the more "simple" test for you. All I really knew was that a long-standing test suddenly stopped working with the new release.

I just tested and confirmed 2.17 indeed fixes the problem. Many thanks for the prompt fix.