]> source.dussan.org Git - nextcloud-server.git/commitdiff
Fix DAV mimetype search 17730/head
authorRoeland Jago Douma <roeland@famdouma.nl>
Mon, 28 Oct 2019 20:56:05 +0000 (21:56 +0100)
committerRoeland Jago Douma <roeland@famdouma.nl>
Mon, 28 Oct 2019 20:56:29 +0000 (21:56 +0100)
Fixes #15048
Catches the case where a full mimetype is sumbitted in the where like
clause. Before we didn't catch this and it was just forwarded as is
causing invalid queries.

Signed-off-by: Roeland Jago Douma <roeland@famdouma.nl>
lib/private/Files/Cache/QuerySearchHelper.php

index ac64ba5c592cdc196ab130ecb9a6f0cad2391e51..2d9d8f374f73633d53908ca6aaaf39729ce23493 100644 (file)
@@ -136,16 +136,19 @@ class QuerySearchHelper {
                $type = $operator->getType();
                if ($field === 'mimetype') {
                        if ($operator->getType() === ISearchComparison::COMPARE_EQUAL) {
-                               $value = $this->mimetypeLoader->getId($value);
+                               $value = (int)$this->mimetypeLoader->getId($value);
                        } else if ($operator->getType() === ISearchComparison::COMPARE_LIKE) {
                                // transform "mimetype='foo/%'" to "mimepart='foo'"
                                if (preg_match('|(.+)/%|', $value, $matches)) {
                                        $field = 'mimepart';
-                                       $value = $this->mimetypeLoader->getId($matches[1]);
+                                       $value = (int)$this->mimetypeLoader->getId($matches[1]);
                                        $type = ISearchComparison::COMPARE_EQUAL;
-                               }
-                               if (strpos($value, '%') !== false) {
+                               } else if (strpos($value, '%') !== false) {
                                        throw new \InvalidArgumentException('Unsupported query value for mimetype: ' . $value . ', only values in the format "mime/type" or "mime/%" are supported');
+                               } else {
+                                       $field = 'mimetype';
+                                       $value = (int)$this->mimetypeLoader->getId($value);
+                                       $type = ISearchComparison::COMPARE_EQUAL;
                                }
                        }
                } else if ($field === 'favorite') {