From cd7aff47e163c1213e072af02fbbeafa11cf64e1 Mon Sep 17 00:00:00 2001 From: Robin McCorkell Date: Tue, 22 Sep 2015 13:34:07 +0100 Subject: [PATCH 1/4] Introduce a few new mimetypes for code --- core/js/mimetypelist.js | 62 +++++++++++++--------- resources/config/mimetypealiases.dist.json | 28 ++++++---- resources/config/mimetypemapping.dist.json | 7 ++- 3 files changed, 61 insertions(+), 36 deletions(-) diff --git a/core/js/mimetypelist.js b/core/js/mimetypelist.js index af2ad73c51..760d7baab7 100644 --- a/core/js/mimetypelist.js +++ b/core/js/mimetypelist.js @@ -9,23 +9,26 @@ OC.MimeTypeList={ aliases: { "application/coreldraw": "image", - "application/font-sfnt": "font", - "application/font-woff": "font", - "application/illustrator": "image/vector", + "application/epub+zip": "text", + "application/font-sfnt": "image", + "application/font-woff": "image", + "application/illustrator": "image", + "application/javascript": "text/code", "application/json": "text/code", - "application/msaccess": "database", + "application/msaccess": "file", "application/msexcel": "x-office/spreadsheet", "application/mspowerpoint": "x-office/presentation", "application/msword": "x-office/document", "application/octet-stream": "file", - "application/postscript": "image/vector", + "application/postscript": "image", + "application/rss+xml": "application/xml", "application/vnd.android.package-archive": "package/x-generic", "application/vnd.ms-excel": "x-office/spreadsheet", "application/vnd.ms-excel.addin.macroEnabled.12": "x-office/spreadsheet", "application/vnd.ms-excel.sheet.binary.macroEnabled.12": "x-office/spreadsheet", "application/vnd.ms-excel.sheet.macroEnabled.12": "x-office/spreadsheet", "application/vnd.ms-excel.template.macroEnabled.12": "x-office/spreadsheet", - "application/vnd.ms-fontobject": "font", + "application/vnd.ms-fontobject": "image", "application/vnd.ms-powerpoint": "x-office/presentation", "application/vnd.ms-powerpoint.addin.macroEnabled.12": "x-office/presentation", "application/vnd.ms-powerpoint.presentation.macroEnabled.12": "x-office/presentation", @@ -49,10 +52,11 @@ OC.MimeTypeList={ "application/vnd.openxmlformats-officedocument.wordprocessingml.document": "x-office/document", "application/vnd.openxmlformats-officedocument.wordprocessingml.template": "x-office/document", "application/x-7z-compressed": "package/x-generic", + "application/x-cbr": "text", "application/x-compressed": "package/x-generic", "application/x-dcraw": "image", "application/x-deb": "package/x-generic", - "application/x-font": "font", + "application/x-font": "image", "application/x-gimp": "image", "application/x-gzip": "package/x-generic", "application/x-perl": "text/code", @@ -64,33 +68,39 @@ OC.MimeTypeList={ "application/xml": "text/html", "application/yaml": "text/code", "application/zip": "package/x-generic", + "database": "file", "httpd/unix-directory": "dir", - "image/svg+xml": "image/vector", "text/css": "text/code", "text/csv": "x-office/spreadsheet", - "text/x-shellscript": "text/code" + "text/html": "text/code", + "text/x-c": "text/code", + "text/x-h": "text/code", + "text/x-java-source": "text/code", + "text/x-python": "text/code", + "text/x-shellscript": "text/code", + "web": "text/code" }, files: [ - "application-pdf", - "application", - "audio", - "file", - "folder-drag-accept", - "folder-external", - "folder-public", - "folder-shared", - "folder-starred", - "folder", - "image", - "package-x-generic", - "text-calendar", - "text-code", - "text-vcard", - "text", "video", + "folder-drag-accept", + "folder-starred", + "folder-public", + "package-x-generic", + "text", + "folder-external", + "text-vcard", + "application", + "text-code", + "x-office-spreadsheet", + "application-pdf", + "folder", "x-office-document", + "text-calendar", "x-office-presentation", - "x-office-spreadsheet" + "file", + "folder-shared", + "image", + "audio" ], themes: [] }; diff --git a/resources/config/mimetypealiases.dist.json b/resources/config/mimetypealiases.dist.json index 3d6c5edc13..d0019c4f0a 100644 --- a/resources/config/mimetypealiases.dist.json +++ b/resources/config/mimetypealiases.dist.json @@ -9,23 +9,26 @@ "application/coreldraw": "image", - "application/font-sfnt": "font", - "application/font-woff": "font", - "application/illustrator": "image/vector", + "application/epub+zip": "text", + "application/font-sfnt": "image", + "application/font-woff": "image", + "application/illustrator": "image", + "application/javascript": "text/code", "application/json": "text/code", - "application/msaccess": "database", + "application/msaccess": "file", "application/msexcel": "x-office/spreadsheet", "application/mspowerpoint": "x-office/presentation", "application/msword": "x-office/document", "application/octet-stream": "file", - "application/postscript": "image/vector", + "application/postscript": "image", + "application/rss+xml": "application/xml", "application/vnd.android.package-archive": "package/x-generic", "application/vnd.ms-excel": "x-office/spreadsheet", "application/vnd.ms-excel.addin.macroEnabled.12": "x-office/spreadsheet", "application/vnd.ms-excel.sheet.binary.macroEnabled.12": "x-office/spreadsheet", "application/vnd.ms-excel.sheet.macroEnabled.12": "x-office/spreadsheet", "application/vnd.ms-excel.template.macroEnabled.12": "x-office/spreadsheet", - "application/vnd.ms-fontobject": "font", + "application/vnd.ms-fontobject": "image", "application/vnd.ms-powerpoint": "x-office/presentation", "application/vnd.ms-powerpoint.addin.macroEnabled.12": "x-office/presentation", "application/vnd.ms-powerpoint.presentation.macroEnabled.12": "x-office/presentation", @@ -49,10 +52,11 @@ "application/vnd.openxmlformats-officedocument.wordprocessingml.document": "x-office/document", "application/vnd.openxmlformats-officedocument.wordprocessingml.template": "x-office/document", "application/x-7z-compressed": "package/x-generic", + "application/x-cbr": "text", "application/x-compressed": "package/x-generic", "application/x-dcraw": "image", "application/x-deb": "package/x-generic", - "application/x-font": "font", + "application/x-font": "image", "application/x-gimp": "image", "application/x-gzip": "package/x-generic", "application/x-perl": "text/code", @@ -64,10 +68,16 @@ "application/xml": "text/html", "application/yaml": "text/code", "application/zip": "package/x-generic", + "database": "file", "httpd/unix-directory": "dir", - "image/svg+xml": "image/vector", "text/css": "text/code", "text/csv": "x-office/spreadsheet", - "text/x-shellscript": "text/code" + "text/html": "text/code", + "text/x-c": "text/code", + "text/x-h": "text/code", + "text/x-java-source": "text/code", + "text/x-python": "text/code", + "text/x-shellscript": "text/code", + "web": "text/code" } diff --git a/resources/config/mimetypemapping.dist.json b/resources/config/mimetypemapping.dist.json index 79b0ca6524..e7c0887181 100644 --- a/resources/config/mimetypemapping.dist.json +++ b/resources/config/mimetypemapping.dist.json @@ -27,6 +27,7 @@ "cbz": ["application/x-cbr"], "cc": ["text/x-c"], "cdr": ["application/coreldraw"], + "class": ["application/java"], "cnf": ["text/plain"], "conf": ["text/plain"], "cpp": ["text/x-c++src"], @@ -35,7 +36,7 @@ "csv": ["text/csv"], "cvbdl": ["application/x-cbr"], "c": ["text/x-c"], - "c++": ["text/x-c++src"], + "c++": ["text/x-c"], "dcr": ["image/x-dcraw"], "deb": ["application/x-deb"], "dng": ["image/x-dcraw"], @@ -57,12 +58,14 @@ "gzip": ["application/x-gzip"], "h": ["text/x-h"], "hh": ["text/x-h"], + "hpp": ["text/x-h"], "html": ["text/html", "text/plain"], "htm": ["text/html", "text/plain"], "ical": ["text/calendar"], "ics": ["text/calendar"], "iiq": ["image/x-dcraw"], "impress": ["text/impress"], + "java": ["text/x-java-source"], "jpeg": ["image/jpeg"], "jpg": ["image/jpeg"], "jps": ["image/jpeg"], @@ -130,6 +133,8 @@ "raf": ["image/x-dcraw"], "rar": ["application/x-rar-compressed"], "reveal": ["text/reveal"], + "rss": ["application/rss+xml"], + "rtf": ["text/rtf"], "rw2": ["image/x-dcraw"], "sgf": ["application/sgf"], "sh-lib": ["text/x-shellscript"], From aeb20675dd9679331b0de8f7ebf72ed0b0815742 Mon Sep 17 00:00:00 2001 From: Robin McCorkell Date: Tue, 22 Sep 2015 14:39:02 +0100 Subject: [PATCH 2/4] Allow recursive mimetype aliases application/xml -> text/html -> text/code --- core/js/mimetype.js | 2 +- lib/private/files/type/detection.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/core/js/mimetype.js b/core/js/mimetype.js index d22b0a2378..b0de8eb841 100644 --- a/core/js/mimetype.js +++ b/core/js/mimetype.js @@ -70,7 +70,7 @@ OC.MimeType = { return undefined; } - if (mimeType in OC.MimeTypeList.aliases) { + while (mimeType in OC.MimeTypeList.aliases) { mimeType = OC.MimeTypeList.aliases[mimeType]; } if (mimeType in OC.MimeType._mimeTypeIcons) { diff --git a/lib/private/files/type/detection.php b/lib/private/files/type/detection.php index 0c647ab44c..dc8aff2f30 100644 --- a/lib/private/files/type/detection.php +++ b/lib/private/files/type/detection.php @@ -269,7 +269,7 @@ class Detection implements IMimeTypeDetector { public function mimeTypeIcon($mimetype) { $this->loadAliases(); - if (isset($this->mimeTypeAlias[$mimetype])) { + while (isset($this->mimeTypeAlias[$mimetype])) { $mimetype = $this->mimeTypeAlias[$mimetype]; } if (isset($this->mimetypeIcons[$mimetype])) { From 57ceee13a964ac949717891e13af1990779ad841 Mon Sep 17 00:00:00 2001 From: Roeland Jago Douma Date: Tue, 22 Sep 2015 17:56:48 +0200 Subject: [PATCH 3/4] Updated some mimetypes * c++ and cpp now both map to code --- core/js/mimetypelist.js | 1 + resources/config/mimetypealiases.dist.json | 1 + resources/config/mimetypemapping.dist.json | 2 +- 3 files changed, 3 insertions(+), 1 deletion(-) diff --git a/core/js/mimetypelist.js b/core/js/mimetypelist.js index 760d7baab7..43f01273f5 100644 --- a/core/js/mimetypelist.js +++ b/core/js/mimetypelist.js @@ -74,6 +74,7 @@ OC.MimeTypeList={ "text/csv": "x-office/spreadsheet", "text/html": "text/code", "text/x-c": "text/code", + "text/x-c++src": "text/code", "text/x-h": "text/code", "text/x-java-source": "text/code", "text/x-python": "text/code", diff --git a/resources/config/mimetypealiases.dist.json b/resources/config/mimetypealiases.dist.json index d0019c4f0a..ed471f228e 100644 --- a/resources/config/mimetypealiases.dist.json +++ b/resources/config/mimetypealiases.dist.json @@ -74,6 +74,7 @@ "text/csv": "x-office/spreadsheet", "text/html": "text/code", "text/x-c": "text/code", + "text/x-c++src": "text/code", "text/x-h": "text/code", "text/x-java-source": "text/code", "text/x-python": "text/code", diff --git a/resources/config/mimetypemapping.dist.json b/resources/config/mimetypemapping.dist.json index e7c0887181..e26ec7038b 100644 --- a/resources/config/mimetypemapping.dist.json +++ b/resources/config/mimetypemapping.dist.json @@ -36,7 +36,7 @@ "csv": ["text/csv"], "cvbdl": ["application/x-cbr"], "c": ["text/x-c"], - "c++": ["text/x-c"], + "c++": ["text/x-c++src"], "dcr": ["image/x-dcraw"], "deb": ["application/x-deb"], "dng": ["image/x-dcraw"], From c80dd82fe4c197cb09344a2ce25f790cd597b792 Mon Sep 17 00:00:00 2001 From: Roeland Jago Douma Date: Fri, 2 Oct 2015 15:28:03 +0200 Subject: [PATCH 4/4] Added mimetype repair step * Version number increased --- lib/repair/repairmimetypes.php | 52 ++++++++++++++++++++ tests/lib/repair/repairmimetypes.php | 72 ++++++++++++++++++++++++++++ version.php | 2 +- 3 files changed, 125 insertions(+), 1 deletion(-) diff --git a/lib/repair/repairmimetypes.php b/lib/repair/repairmimetypes.php index db11f526ad..b9cd42f313 100644 --- a/lib/repair/repairmimetypes.php +++ b/lib/repair/repairmimetypes.php @@ -250,6 +250,39 @@ class RepairMimeTypes extends BasicEmitter implements \OC\RepairStep { self::updateMimetypes($updatedMimetypes); } + private function introduceJavaMimeType() { + $updatedMimetypes = array( + 'class' => 'application/java', + 'java' => 'text/x-java-source', + ); + + self::updateMimetypes($updatedMimetypes); + } + + private function introduceHppMimeType() { + $updatedMimetypes = array( + 'hpp' => 'text/x-h', + ); + + self::updateMimetypes($updatedMimetypes); + } + + private function introduceRssMimeType() { + $updatedMimetypes = array( + 'rss' => 'application/rss+xml', + ); + + self::updateMimetypes($updatedMimetypes); + } + + private function introduceRtfMimeType() { + $updatedMimetypes = array( + 'rtf' => 'text/rtf', + ); + + self::updateMimetypes($updatedMimetypes); + } + /** * Fix mime types */ @@ -294,5 +327,24 @@ class RepairMimeTypes extends BasicEmitter implements \OC\RepairStep { $this->emit('\OC\Repair', 'info', array('Fixed Yaml/Yml mime types')); } } + + // Mimetype updates from #19272 + if (version_compare($ocVersionFromBeforeUpdate, '8.2.0.8', '<')) { + if ($this->introduceJavaMimeType()) { + $this->emit('\OC\Repair', 'info', array('Fixed java/class mime types')); + } + + if ($this->introduceHppMimeType()) { + $this->emit('\OC\Repair', 'info', array('Fixed hpp mime type')); + } + + if ($this->introduceRssMimeType()) { + $this->emit('\OC\Repair', 'info', array('Fixed rss mime type')); + } + + if ($this->introduceRtfMimeType()) { + $this->emit('\OC\Repair', 'info', array('Fixed rtf mime type')); + } + } } } diff --git a/tests/lib/repair/repairmimetypes.php b/tests/lib/repair/repairmimetypes.php index 3c100b808c..0288a476ed 100644 --- a/tests/lib/repair/repairmimetypes.php +++ b/tests/lib/repair/repairmimetypes.php @@ -282,6 +282,68 @@ class RepairMimeTypes extends \Test\TestCase { $this->renameMimeTypes($currentMimeTypes, $fixedMimeTypes); } + /** + * Test renaming the java mime types + */ + public function testRenameJavaMimeType() { + $currentMimeTypes = [ + ['test.java', 'application/octet-stream'], + ['test.class', 'application/octet-stream'], + ]; + + $fixedMimeTypes = [ + ['test.java', 'text/x-java-source'], + ['test.class', 'application/java'], + ]; + + $this->renameMimeTypes($currentMimeTypes, $fixedMimeTypes); + } + + /** + * Test renaming the hpp mime type + */ + public function testRenameHppMimeType() { + $currentMimeTypes = [ + ['test.hpp', 'application/octet-stream'], + ]; + + $fixedMimeTypes = [ + ['test.hpp', 'text/x-h'], + ]; + + $this->renameMimeTypes($currentMimeTypes, $fixedMimeTypes); + } + + /** + * Test renaming the rss mime type + */ + public function testRenameRssMimeType() { + $currentMimeTypes = [ + ['test.rss', 'application/octet-stream'], + ]; + + $fixedMimeTypes = [ + ['test.rss', 'application/rss+xml'], + ]; + + $this->renameMimeTypes($currentMimeTypes, $fixedMimeTypes); + } + + /** + * Test renaming the hpp mime type + */ + public function testRenameRtfMimeType() { + $currentMimeTypes = [ + ['test.rtf', 'application/octet-stream'], + ]; + + $fixedMimeTypes = [ + ['test.rtf', 'text/rtf'], + ]; + + $this->renameMimeTypes($currentMimeTypes, $fixedMimeTypes); + } + /** * Test renaming and splitting old office mime types when * new ones already exist @@ -399,6 +461,11 @@ class RepairMimeTypes extends \Test\TestCase { ['test.cnf', 'text/plain'], ['test.yaml', 'application/yaml'], ['test.yml', 'application/yaml'], + ['test.java', 'text/x-java-source'], + ['test.class', 'application/java'], + ['test.hpp', 'text/x-h'], + ['test.rss', 'application/rss+xml'], + ['test.rtf', 'text/rtf'], ]; $fixedMimeTypes = [ @@ -438,6 +505,11 @@ class RepairMimeTypes extends \Test\TestCase { ['test.cnf', 'text/plain'], ['test.yaml', 'application/yaml'], ['test.yml', 'application/yaml'], + ['test.java', 'text/x-java-source'], + ['test.class', 'application/java'], + ['test.hpp', 'text/x-h'], + ['test.rss', 'application/rss+xml'], + ['test.rtf', 'text/rtf'], ]; $this->renameMimeTypes($currentMimeTypes, $fixedMimeTypes); diff --git a/version.php b/version.php index 925e897d1a..7ba6c3d93b 100644 --- a/version.php +++ b/version.php @@ -23,7 +23,7 @@ // We only can count up. The 4. digit is only for the internal patchlevel to trigger DB upgrades // between betas, final and RCs. This is _not_ the public version number. Reset minor/patchlevel // when updating major/minor version number. -$OC_Version = array(8, 2, 0, 7); +$OC_Version = array(8, 2, 0, 8); // The human readable string $OC_VersionString = '8.2 beta1';