helios-ag / FMElfinderBundle

:file_folder: ElFinderBundle provides ElFinder integration with TinyMCE, CKEditor, Summernote editors
MIT License
275 stars 128 forks source link

ElFinderLoader::encode($path) does not return any valid result #368

Closed ofriedrich closed 4 years ago

ofriedrich commented 4 years ago
Issue Type:

Please pick one and delete the rest:

Bundle Version:

Master

Summary:

We need to encode a path into a Elfinder specific hash. So we tried to use the FM\ElfinderBundle\Loader\ElFinderLoader:: encode($path) to get the hash for the current path. But the result was always empty.

Steps To Reproduce:

In a properly configured project create a controller like this:

    /**
     * @Route("/elfinder/path-to-hash/{instance}/{homeFolder}", methods={"GET"})
     * @param Request $request
     * @param string $instance
     * @param string $homeFolder
     * @return JsonResponse
     */
    public function pathToHash(Request $request, string $instance, string $homeFolder): JsonResponse
        $loader = $this->get('fm_elfinder.loader');
        $loader->initBridge($instance);
        if ($loader instanceof ElFinderLoader) {
            $loader->setSession(new ElFinderSession($this->get('session')));
        }
        $path = $request->query->get('path');
        $hash = $loader->encode($path);
        return new JsonResponse($hash);
}

Open your browser with the url containing the path in the query string.

Expected Results:

The response should contain the hash for the given path.

Actual Results:

The response always is an empty string.

Possible solution

https://github.com/helios-ag/FMElfinderBundle/blob/52359fbe5560dae93f021ed2e750a2f812bdb335/src/Loader/ElFinderLoader.php#L120

            $aPathEncoded[$hashId] = $volume->getPath($path);

change into:

            $aPathEncoded[$hashId] = $volume->getHash($path);

The getPath-method converts a hash into a path. The getHash-method converts a path into a hash!

helios-ag commented 4 years ago

Changed in v10