nutch-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "ASF GitHub Bot (JIRA)" <j...@apache.org>
Subject [jira] [Commented] (NUTCH-2606) MIME detection is wrong for plain-text documents send as Content-Type "application/msword"
Date Mon, 19 Nov 2018 20:53:00 GMT

    [ https://issues.apache.org/jira/browse/NUTCH-2606?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16692254#comment-16692254
] 

ASF GitHub Bot commented on NUTCH-2606:
---------------------------------------

sebastian-nagel closed pull request #392: NUTCH-2606 MIME detection is wrong for plain-text
documents send as Content-Type "application/msword"
URL: https://github.com/apache/nutch/pull/392
 
 
   

This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:

As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):

diff --git a/src/java/org/apache/nutch/util/MimeUtil.java b/src/java/org/apache/nutch/util/MimeUtil.java
index d380427ae..443341ecd 100644
--- a/src/java/org/apache/nutch/util/MimeUtil.java
+++ b/src/java/org/apache/nutch/util/MimeUtil.java
@@ -200,8 +200,7 @@ public String autoResolveContentType(String typeName, String url, byte[]
data) {
       }
 
       if (magicType != null && !magicType.equals(MimeTypes.OCTET_STREAM)
-          && !magicType.equals(MimeTypes.PLAIN_TEXT) && retType != null
-          && !retType.equals(magicType)) {
+          && retType != null && !retType.equals(magicType)) {
 
         // If magic enabled and the current mime type differs from that of the
         // one returned from the magic, take the magic mimeType
diff --git a/src/test/org/apache/nutch/util/TestMimeUtil.java b/src/test/org/apache/nutch/util/TestMimeUtil.java
index d0b45dbac..72a42b457 100644
--- a/src/test/org/apache/nutch/util/TestMimeUtil.java
+++ b/src/test/org/apache/nutch/util/TestMimeUtil.java
@@ -68,7 +68,16 @@
           "<?xml version=\"1.0\"?>\n<html xmlns=\"http://www.w3.org/1999/xhtml\">"
               + "<html>\n<head>\n"
               + "<meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\"
/>"
-              + "</head>\n<body>Hello, World!</body></html>" } };
+              + "</head>\n<body>Hello, World!</body></html>" },
+      { /*
+         * test detection of plain-text documents with erroneous Content-Type
+         * sent in HTTP header (NUTCH-2606)
+         */
+          "text/plain", // correct MIME type
+          "test.doc", // erroneously indicates MS-Word document
+          "application/msword", // erroneous Content-Type
+          "This is a plain text document",
+          "requires-mime-magic" } };
 
   public static String[][] binaryFiles = { {
       "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
@@ -99,6 +108,9 @@ public void testWithMimeMagic() {
   /** use only HTTP Content-Type (if given) and URL pattern */
   public void testWithoutMimeMagic() {
     for (String[] testPage : textBasedFormats) {
+      if (testPage.length > 4 && "requires-mime-magic".equals(testPage[4])) {
+        continue;
+      }
       String mimeType = getMimeType(urlPrefix + testPage[1],
           testPage[3].getBytes(defaultCharset), testPage[2], false);
       assertEquals("", testPage[0], mimeType);


 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


> MIME detection is wrong for plain-text documents send as Content-Type "application/msword"
> ------------------------------------------------------------------------------------------
>
>                 Key: NUTCH-2606
>                 URL: https://issues.apache.org/jira/browse/NUTCH-2606
>             Project: Nutch
>          Issue Type: Bug
>    Affects Versions: 1.14
>            Reporter: Sebastian Nagel
>            Priority: Minor
>             Fix For: 1.16
>
>
> Plain-text documents send as Content-Type "application/msword" are tried to parse as
Word documents. The MIME detection should be fixed, so that these are correctly identified
as plain-text documents. See NUTCH-2603 and https://www.atnf.csiro.au/computing/software/gipsy/doc/update.doc



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)

Mime
View raw message