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 {
}
public function getUrl() {
return urlencode($this->getPath());
}
public function getRealpath() {
return $this->_attribs['Realpath'];
}
......
......@@ -44,7 +44,7 @@ class ZendAfi_Controller_Plugin_Manager_FileManager extends ZendAfi_Controller_P
},
'label' => $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',
'into' => $model->getId()],
......@@ -104,7 +104,7 @@ class ZendAfi_Controller_Plugin_Manager_FileManager extends ZendAfi_Controller_P
'data-popup' => 'true',
'class' => $model->isWritable() ? null : 'disabled'])],
['url' => $model->getPath(),
['url' => $model->getUrl(),
'icon' => '',
'caption' => function($model) {
if($model->isFile())
......
......@@ -50,7 +50,7 @@ class ZendAfi_View_Helper_Admin_FileManager_File extends ZendAfi_View_Helper_Bas
];
$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()
? $this->view->tagAnchor($url,
......
......@@ -1004,7 +1004,7 @@ Class FileManagerControllerDispatchImageTest extends FileManagerControllerTestCa
/** @test */
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());
}
......@@ -1489,10 +1489,10 @@ class FileManagerControllerWithSpecialCharTest extends FileManagerControllerTest
public function setUp() {
parent::setUp();
$image = (new Class_FileManager)
->setId('userfiles/my\'directory/new_image.jpg')
->setPath('userfiles/my\'directory/new_image.jpg')
->setParentPath('userfiles/my\'directory')
->setName('new_image.jpg')
->setId('userfiles/my\'direct"ory/new\'_ima"ge.jpg')
->setPath('userfiles/my\'direct"ory/new\'_ima"ge.jpg')
->setParentPath('userfiles/my\'direct"ory')
->setName('new\'_ima"ge.jpg')
->setDir(false)
->setExtension('jpg')
->setDimensions('1920x1080');
......@@ -1500,27 +1500,36 @@ class FileManagerControllerWithSpecialCharTest extends FileManagerControllerTest
Class_FileManager::getFileSystem()
->whenCalled('directoryAt')
->with('userfiles/my\'directory/new_image.jpg')
->with('userfiles/my\'direct"ory/new\'_ima"ge.jpg')
->answers(null)
->whenCalled('fileAt')
->with('userfiles/my\'directory/new_image.jpg')
->with('userfiles/my\'direct"ory/new\'_ima"ge.jpg')
->answers($image)
->whenCalled('directoryAt')
->with('userfiles/my\'directory')
->with('userfiles/my\'direct"ory')
->answers(null)
->whenCalled('fileAt')
->with('userfiles/my\'directory')
->answers(null) ;
->with('userfiles/my\'direct"ory')
->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 */
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