Commit e9c5d1d0 authored by Ghislain Loas's avatar Ghislain Loas
Browse files

hotline #70402 fix url when files and folders got special chars

parent 37965235
...@@ -410,6 +410,11 @@ class Class_FileManager extends Class_Entity { ...@@ -410,6 +410,11 @@ class Class_FileManager extends Class_Entity {
} }
public function getUrl() {
return urlencode($this->getPath());
}
public function getRealpath() { public function getRealpath() {
return $this->_attribs['Realpath']; return $this->_attribs['Realpath'];
} }
......
...@@ -44,7 +44,7 @@ class ZendAfi_Controller_Plugin_Manager_FileManager extends ZendAfi_Controller_P ...@@ -44,7 +44,7 @@ class ZendAfi_Controller_Plugin_Manager_FileManager extends ZendAfi_Controller_P
}, },
'label' => $this->_('Sélectionner "%s"', $model->getName()), 'label' => $this->_('Sélectionner "%s"', $model->getName()),
'anchorOptions' => array_filter(['title' => $this->_('Sélectionner "%s"', $model->getName()), 'anchorOptions' => array_filter(['title' => $this->_('Sélectionner "%s"', $model->getName()),
'onclick' => "$(this).selectItemForCKEditor('" . Class_Url::relative(str_replace(["'", '"'], ["\'", '"'], $model->getId())) . "');"])], 'onclick' => "$(this).selectItemForCKEditor('" . Class_Url::relative(str_replace(["'", '"'], ['%27', '%22'], $model->getId())) . "');"])],
['url' => ['action' => 'create', ['url' => ['action' => 'create',
'into' => $model->getId()], 'into' => $model->getId()],
...@@ -104,7 +104,7 @@ class ZendAfi_Controller_Plugin_Manager_FileManager extends ZendAfi_Controller_P ...@@ -104,7 +104,7 @@ class ZendAfi_Controller_Plugin_Manager_FileManager extends ZendAfi_Controller_P
'data-popup' => 'true', 'data-popup' => 'true',
'class' => $model->isWritable() ? null : 'disabled'])], 'class' => $model->isWritable() ? null : 'disabled'])],
['url' => $model->getPath(), ['url' => $model->getUrl(),
'icon' => '', 'icon' => '',
'caption' => function($model) { 'caption' => function($model) {
if($model->isFile()) if($model->isFile())
......
...@@ -50,7 +50,7 @@ class ZendAfi_View_Helper_Admin_FileManager_File extends ZendAfi_View_Helper_Bas ...@@ -50,7 +50,7 @@ class ZendAfi_View_Helper_Admin_FileManager_File extends ZendAfi_View_Helper_Bas
]; ];
$dl = $this->_tag('dl', implode(array_filter($dt))); $dl = $this->_tag('dl', implode(array_filter($dt)));
$url = $this->view->absoluteUrl($file->getPath(), null, true) . '?version='. time(); // force reload image $url = $this->view->absoluteUrl($file->getUrl(), null, true) . '?version='. time(); // force reload image
$open_new_tab = ($file->isFile() $open_new_tab = ($file->isFile()
? $this->view->tagAnchor($url, ? $this->view->tagAnchor($url,
......
...@@ -1004,7 +1004,7 @@ Class FileManagerControllerDispatchImageTest extends FileManagerControllerTestCa ...@@ -1004,7 +1004,7 @@ Class FileManagerControllerDispatchImageTest extends FileManagerControllerTestCa
/** @test */ /** @test */
public function downloadCaliforniaAnchorShouldBePresent() { public function downloadCaliforniaAnchorShouldBePresent() {
$this->assertXPathContentContains('//div//a[contains(@href, "userfiles/california.jpg")]', 'Télécharger'); $this->assertXPathContentContains('//div//a[contains(@href, "userfiles%2Fcalifornia.jpg")]', 'Télécharger', $this->_response->getBody());
} }
...@@ -1067,7 +1067,7 @@ class FileManagerControllerWithImageInArticleTest extends FileManagerControllerT ...@@ -1067,7 +1067,7 @@ class FileManagerControllerWithImageInArticleTest extends FileManagerControllerT
$banner = $this->fixture('Class_Article', $banner = $this->fixture('Class_Article',
['id' => 1, ['id' => 1,
'titre' => 'Banner article', 'titre' => 'Banner article',
'contenu' => '<img src="https:// ' . BASE_URL . 'userfiles/image/home.jpg"></>']); 'contenu' => '<img src="https:// ' . BASE_URL . 'userfiles/image/home.jpg"></>']);
$disk = Class_FileManager::getFileSystem() $disk = Class_FileManager::getFileSystem()
->whenCalled('directoryAt') ->whenCalled('directoryAt')
...@@ -1489,10 +1489,10 @@ class FileManagerControllerWithSpecialCharTest extends FileManagerControllerTest ...@@ -1489,10 +1489,10 @@ class FileManagerControllerWithSpecialCharTest extends FileManagerControllerTest
public function setUp() { public function setUp() {
parent::setUp(); parent::setUp();
$image = (new Class_FileManager) $image = (new Class_FileManager)
->setId('userfiles/my\'directory/new_image.jpg') ->setId('userfiles/my\'direct"ory/new\'_ima"ge.jpg')
->setPath('userfiles/my\'directory/new_image.jpg') ->setPath('userfiles/my\'direct"ory/new\'_ima"ge.jpg')
->setParentPath('userfiles/my\'directory') ->setParentPath('userfiles/my\'direct"ory')
->setName('new_image.jpg') ->setName('new\'_ima"ge.jpg')
->setDir(false) ->setDir(false)
->setExtension('jpg') ->setExtension('jpg')
->setDimensions('1920x1080'); ->setDimensions('1920x1080');
...@@ -1500,27 +1500,36 @@ class FileManagerControllerWithSpecialCharTest extends FileManagerControllerTest ...@@ -1500,27 +1500,36 @@ class FileManagerControllerWithSpecialCharTest extends FileManagerControllerTest
Class_FileManager::getFileSystem() Class_FileManager::getFileSystem()
->whenCalled('directoryAt') ->whenCalled('directoryAt')
->with('userfiles/my\'directory/new_image.jpg') ->with('userfiles/my\'direct"ory/new\'_ima"ge.jpg')
->answers(null) ->answers(null)
->whenCalled('fileAt') ->whenCalled('fileAt')
->with('userfiles/my\'directory/new_image.jpg') ->with('userfiles/my\'direct"ory/new\'_ima"ge.jpg')
->answers($image) ->answers($image)
->whenCalled('directoryAt') ->whenCalled('directoryAt')
->with('userfiles/my\'directory') ->with('userfiles/my\'direct"ory')
->answers(null) ->answers(null)
->whenCalled('fileAt') ->whenCalled('fileAt')
->with('userfiles/my\'directory') ->with('userfiles/my\'direct"ory')
->answers(null) ; ->answers(null);
$this->dispatch('/admin/file-manager/index?browser=userfiles%2Fmy%27directory%2Fnew_image.jpg&selectable_extensions=jpg;png', true); $this->dispatch('/admin/file-manager/index?browser=userfiles%2Fmy%27direct"ory%2Fnew%27_ima"ge.jpg&selectable_extensions=jpg;png', true);
} }
/** @test */
/** @test */
public function selectButtonShouldBePresent() { public function selectButtonShouldBePresent() {
$this->assertXPathContentContains('//div//a[contains(@onclick, "$(this).selectItemForCKEditor(\'/stl/userfiles/my%27directory/coffee-mug.png\');")]', 'Sélectionner', $this->_response->getBody()); $this->assertXPathContentContains('//div//a[contains(@onclick, "$(this).selectItemForCKEditor(")][contains(@onclick, "/userfiles/my%27direct%22ory/new%27_ima%22ge.jpg")]', 'Sélectionner');
} }
/** @test */
public function accessInNewTabShouldBePresent() {
$this->assertXPathContentContains('//div//a[contains(@href, "/userfiles%2Fmy%27direct%22ory%2Fnew%27_ima%22ge.jpg?version=")][@target="_blank"]', 'Accéder à ');
}
/** @test */
public function downloadLinkShouldBePresent() {
$this->assertXPathContentContains('//div//a[contains(@href, "/userfiles%2Fmy%27direct%22ory%2Fnew%27_ima%22ge.jpg")]', 'Télécharger');
}
} }
\ No newline at end of file
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