- Issue created by @Anybody
- First commit to issue fork.
- Merge request !98Updated generateHash() method to remove leading, trailing slashes and... → (Open) created by ameymudras
Redirect::generateHash()
is a public method and can therefor be used by extending modules, which makes sense and is helpful.
On the other hand, it should (eventually) ensure consistent handling.
/**
* Generates a unique hash for identification purposes.
*
* @param string $source_path
* Source path of the redirect.
* @param array $source_query
* Source query as an array.
* @param string $language
* Redirect language.
*
* @return string
* Base 64 hash.
*/
public static function generateHash($source_path, array $source_query, $language) {
$hash = [
'source' => mb_strtolower($source_path),
'language' => $language,
];
if (!empty($source_query)) {
$hash['source_query'] = $source_query;
}
redirect_sort_recursive($hash, 'ksort');
return Crypt::hashBase64(serialize($hash));
}
In cases like
🐛
"Delete redirects defined in the spreadsheet" option without functionality?
Active
a project could provide $source_path differently, with other or no preprocessing that currently happens internally in the Redirect module, like:
$this->redirect_source->path = rtrim($this->redirect_source->path, '/');
in the preSave() method.
I guess the method should ensure that the hash is always created on the same normalization of the path as it is saved in the database. For redirect entities that means for example:
so it can be used more safely and unified by the outside world.
See above
Implement consistent handling and normalization for the parameters provided.
Active
1.0
Code