Commit 4e547f52 authored by alexpott's avatar alexpott

Issue #2760797 by mondrake, twistor: MIME type guessing fails for remote stream wrapper URIs

parent fbcd9240
......@@ -53,8 +53,12 @@ public function __construct(StreamWrapperManagerInterface $stream_wrapper_manage
*/
public function guess($path) {
if ($wrapper = $this->streamWrapperManager->getViaUri($path)) {
// Get the real path from the stream wrapper.
$path = $wrapper->realpath();
// Get the real path from the stream wrapper, if available. Files stored
// in remote file systems will not have one.
$real_path = $wrapper->realpath();
if ($real_path !== FALSE) {
$path = $real_path;
}
}
if ($this->sortedGuessers === NULL) {
......
......@@ -20,7 +20,7 @@ class MimeTypeTest extends FileTestBase {
* Test mapping of mimetypes from filenames.
*/
public function testFileMimeTypeDetection() {
$prefix = 'public://';
$prefixes = ['public://', 'private://', 'temporary://', 'dummy-remote://'];
$test_case = array(
'test.jar' => 'application/java-archive',
......@@ -43,8 +43,10 @@ public function testFileMimeTypeDetection() {
// Test using default mappings.
foreach ($test_case as $input => $expected) {
// Test stream [URI].
$output = $guesser->guess($prefix . $input);
$this->assertIdentical($output, $expected, format_string('Mimetype for %input is %output (expected: %expected).', array('%input' => $input, '%output' => $output, '%expected' => $expected)));
foreach ($prefixes as $prefix) {
$output = $guesser->guess($prefix . $input);
$this->assertIdentical($output, $expected, format_string('Mimetype for %input is %output (expected: %expected).', array('%input' => $prefix . $input, '%output' => $output, '%expected' => $expected)));
}
// Test normal path equivalent
$output = $guesser->guess($input);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment