Skip to content

Commit

Permalink
Fix import from external jpeg images
Browse files Browse the repository at this point in the history
  • Loading branch information
Pieter Cappelle committed Dec 24, 2017
1 parent 9c2ce25 commit 8cdf043
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,15 @@ public function move($fileName, $renameFileOff = false)
$read = $this->_readFactory->create($url, DriverPool::HTTPS);
}

//only use filename (for URI with query parameters)
$parsedUrl = parse_url($url);
if ($parsedUrl['path']) {
$urlPathValues = explode('/', $parsedUrl['path']);
if (!empty($urlPathValues)) {
$fileName = end($urlPathValues);
}
}

$fileName = preg_replace('/[^a-z0-9\._-]+/i', '', $fileName);
$this->_directory->writeFile(
$this->_directory->getRelativePath($this->getTmpDir() . '/' . $fileName),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -217,12 +217,32 @@ public function moveFileUrlDataProvider()
[
'$fileUrl' => 'http://test_uploader_file',
'$expectedHost' => 'test_uploader_file',
'$expectedFileName' => 'httptest_uploader_file',
'$expectedFileName' => 'test_uploader_file',
],
[
'$fileUrl' => 'https://!:^&`;file',
'$expectedHost' => '!:^&`;file',
'$expectedFileName' => 'httpsfile',
'$expectedFileName' => 'file',
],
[
'$fileUrl' => 'https://www.google.com/image.jpg',
'$expectedHost' => 'www.google.com/image.jpg',
'$expectedFileName' => 'image.jpg',
],
[
'$fileUrl' => 'https://www.google.com/image.jpg?param=1',
'$expectedHost' => 'www.google.com/image.jpg?param=1',
'$expectedFileName' => 'image.jpg',
],
[
'$fileUrl' => 'https://www.google.com/image.jpg?param=1&param=2',
'$expectedHost' => 'www.google.com/image.jpg?param=1&param=2',
'$expectedFileName' => 'image.jpg',
],
[
'$fileUrl' => 'http://www.google.com/image.jpg?param=1&param=2',
'$expectedHost' => 'www.google.com/image.jpg?param=1&param=2',
'$expectedFileName' => 'image.jpg',
],
];
}
Expand Down

0 comments on commit 8cdf043

Please sign in to comment.