filter/source/textfilterdetect/filterdetect.cxx |   18 +++++++++++++++---
 1 file changed, 15 insertions(+), 3 deletions(-)

New commits:
commit db759800abb62a9abda39c16d6f529d1a76207b6
Author:     Mike Kaganski <mike.kagan...@collabora.com>
AuthorDate: Mon May 3 17:04:04 2021 +0200
Commit:     Mike Kaganski <mike.kagan...@collabora.com>
CommitDate: Tue May 11 07:18:15 2021 +0200

    tdf#123476: also use filter by extension when its service is the same
    
    ... as passed explicitly in the media descriptor, for 0-byte files.
    This makes proper handling for such files when passing module name
    in command line, like --writer for DOCX.
    
    Change-Id: If8fd51e65dcf8a67b2653026f5fc1d5c964074af
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/114924
    Tested-by: Jenkins
    Reviewed-by: Mike Kaganski <mike.kagan...@collabora.com>
    (cherry picked from commit dff586735b6618d9b011823594a33287d8f7f223)
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/114925
    Reviewed-by: Caolán McNamara <caol...@redhat.com>
    (cherry picked from commit a8e84a2d6e634c03d62e17bcc1b617238dcc9eb1)
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/115278
    Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoff...@gmail.com>

diff --git a/filter/source/textfilterdetect/filterdetect.cxx 
b/filter/source/textfilterdetect/filterdetect.cxx
index 09efe5e595e0..19696ec9fa17 100644
--- a/filter/source/textfilterdetect/filterdetect.cxx
+++ b/filter/source/textfilterdetect/filterdetect.cxx
@@ -135,7 +135,7 @@ bool IsHTMLStream( const uno::Reference<io::XInputStream>& 
xInStream )
  * writes the type name to rType, the filter name to rMediaDesc.
  */
 bool HandleEmptyFileUrlByExtension(MediaDescriptor& rMediaDesc, const 
OUString& rExt,
-                                   OUString& rType)
+                                   OUString& rType, OUString& rService)
 {
     OUString aURL = 
rMediaDesc.getUnpackedValueOrDefault(MediaDescriptor::PROP_URL(), OUString());
     if (!tools::isEmptyFileUrl(aURL))
@@ -156,6 +156,7 @@ bool HandleEmptyFileUrlByExtension(MediaDescriptor& 
rMediaDesc, const OUString&
 
     rMediaDesc[MediaDescriptor::PROP_FILTERNAME()] <<= 
pFilter->GetFilterName();
     rType = pFilter->GetTypeName();
+    rService = pFilter->GetServiceName();
     return true;
 }
 }
@@ -216,14 +217,25 @@ OUString SAL_CALL 
PlainTextFilterDetect::detect(uno::Sequence<beans::PropertyVal
         OUString aName = aParser.getName().toAsciiLowerCase();
 
         // Decide which filter to use based on the document service first,
-        // then on extension if that's not available.
+        // then on extension if that's not available. Make exception for 
0-byte files
+        // whose extensions are handled by the same service as passed document 
service.
+        OUString aEmptyType, aEmptyService;
+        bool bEmpty = HandleEmptyFileUrlByExtension(aMediaDesc, aExt, 
aEmptyType, aEmptyService);
+        if (bEmpty && aDocService == aEmptyService)
+        {
+            aDocService.clear(); // don't fallback to text filter, use 
extension-based match
+            // TODO: maybe reset aExt when it's "xls"
+        }
+
         if (aDocService == CALC_DOCSERVICE)
             aMediaDesc[MediaDescriptor::PROP_FILTERNAME()] <<= 
OUString(CALC_TEXT_FILTER);
         else if (aDocService == WRITER_DOCSERVICE)
             aMediaDesc[MediaDescriptor::PROP_FILTERNAME()] <<= 
OUString(WRITER_TEXT_FILTER);
         else if (aExt == "csv" || aExt == "tsv" || aExt == "tab" || aExt == 
"xls" || aName.endsWith(".csv.gz"))
             aMediaDesc[MediaDescriptor::PROP_FILTERNAME()] <<= 
OUString(CALC_TEXT_FILTER);
-        else if (!HandleEmptyFileUrlByExtension(aMediaDesc, aExt, aType))
+        else if (bEmpty)
+            aType = aEmptyType; // aMediaDesc is already updated in 
HandleEmptyFileUrlByExtension
+        else
             aMediaDesc[MediaDescriptor::PROP_FILTERNAME()] <<= 
OUString(WRITER_TEXT_FILTER);
     }
 
_______________________________________________
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits

Reply via email to