Search code examples
phpshopware

Why is there this blacklist in the path name generation of Shopware 6?


While digging the code for image path name generation in Shopware 6, I found that they generate a MD5 sum and then remove certain values.

See here:

https://github.com/shopware/platform/blob/efe7b8ae224c1ef5601c43ff465a9dd5908aa8d3/src/Core/Content/Media/Pathname/PathnameStrategy/AbstractPathNameStrategy.php#L14

private $blacklist = [
    'ad' => 'g0',
];


...


protected function generateMd5Path(string $fromValue): string
{
    $md5hash = md5($fromValue);

    $md5hashSlices = \array_slice(str_split($md5hash, 2), 0, 3);
    $md5hashSlices = array_map(
        function ($slice) {
            return \array_key_exists($slice, $this->blacklist) ? $this->blacklist[$slice] : $slice;
        },
        $md5hashSlices
    );

    return implode('/', $md5hashSlices);
}

What can be the reason for such a code? What is so bad about "ad" ?


Solution

  • I believe image path's with "ad" in the name would be more likely to be blocked by adblockers.