-
-
Notifications
You must be signed in to change notification settings - Fork 4.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Bug]: mimetype inconsistency between Detection.detectPath
and Loader.updateFilecache
#35958
Open
5 of 9 tasks
Labels
0. Needs triage
Pending check for reproducibility or if it fits our roadmap
feature: files
technical debt
Comments
tacruc
added
bug
0. Needs triage
Pending check for reproducibility or if it fits our roadmap
labels
Jan 3, 2023
Possible fixes: public function detectPath($path): string {
$this->loadMappings();
$fileName = basename($path);
// remove versioning extension: name.v1508946057 and transfer extension: name.ocTransferId2057600214.part
$fileName = preg_replace('!((\.v\d+)|((\.ocTransferId\d+)?\.part))$!', '', $fileName);
//try to guess the type by the file extension
$extension = strrchr($fileName, '.');
if ($extension !== false) {
$extension = strtolower($extension);
$extension = substr($extension, 1); //remove leading .
return $this->mimetypes[$extension][0] ?? 'application/octet-stream';
}
return 'application/octet-stream';
} Pros:
Cons: /**
* detect mimetype only based on filename, content of file is not used
*
* @param string $path
* @return string
*/
public function detectPath($path): string {
$this->loadMappings();
$extensions = array_keys($this->mimetypes);
$fileName = basename($path);
// remove versioning extension: name.v1508946057 and transfer extension: name.ocTransferId2057600214.part
$fileName = preg_replace('!((\.v\d+)|((\.ocTransferId\d+)?\.part))$!', '', $fileName);
$fileExtensions = [];
foreach ($extensions as $ext) {
if (str_ends_with('.'.$fileName, '.'.$ext)) $fileExtensions[]=$ext;
}
usort($fileExtensions, function($a, $b) {
return strlen($b) - strlen($a);
});
$extension = array_shift($fileExtensions);
return $this->mimetypes[$extension][0] ?? 'application/octet-stream';
} Pros:
Cons:
/**
* detect mimetype only based on filename, content of file is not used
*
* @param string $path
* @return string
*/
public function detectPath($path): string {
$this->loadMappings();
$fileName = preg_replace('!((\.v\d+)|((\.ocTransferId\d+)?\.part))$!', '', basename($path));
if (preg_match(
'!(^\.(?<ext1>[^\.]+))|(^\.?[^\.]+\.(?<ext2>.+))$!',
$fileName,
$matches)){
$extension = $matches['ext1'] ?? $matches['ext2'];
return $this->mimetypes[$extension][0] ?? 'application/octet-stream';
}
return 'application/octet-stream';
} Pros:
Cons:
|
cc @nextcloud/server for input/feedback on this :) |
tacruc
added a commit
to nextcloud/maps
that referenced
this issue
Jan 7, 2023
…ia ... due to nextcloud/server#35958 Signed-off-by: Arne Hamann <[email protected]>
tacruc
added a commit
to nextcloud/maps
that referenced
this issue
Jan 7, 2023
…ia ... due to nextcloud/server#35958 Signed-off-by: Arne Hamann <[email protected]>
Different fix from @nickvergessen would be: |
joshtrichards
changed the title
[Bug]: mimetype inconsitency between Dectection.detectPath and Loader.updateFilecache
[Bug]: mimetype inconsistency between Sep 8, 2024
Detection.detectPath
and Loader.updateFilecache
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Labels
0. Needs triage
Pending check for reproducibility or if it fits our roadmap
feature: files
technical debt
Bug description
For files named like .ext e.g. ".gpx", ".ext" or ".maps" get different mimetypes by
server/lib/private/Files/Type/Detection.php
Line 195 in ce1dddc
or
server/lib/private/Files/Type/Loader.php
Line 164 in ce1dddc
To clearify its about files which start with a . and then just have the extension.
Therefore existing files get different mime-types then new file.
Steps to reproduce
Expected behavior
Installation method
None
Operating system
None
PHP engine version
None
Web server
None
Database engine version
MySQL
Is this bug present after an update or on a fresh install?
None
Are you using the Nextcloud Server Encryption module?
None
What user-backends are you using?
Configuration report
No response
List of activated Apps
Nextcloud Signing status
No response
Nextcloud Logs
No response
Additional info
No response
The text was updated successfully, but these errors were encountered: