bednee / cooluri

GIT repository for TYPO3 extension CoolUri
7 stars 12 forks source link

Warning in Integration\CoolUri (method extractArraysFromParams) #92

Open aimcom opened 5 years ago

aimcom commented 5 years ago

Line 613 of Classes/Integration/CoolUri.php is source of a warning if there is an array in the GET parameters.

E.g. if there is a param like "&my_extension_plugin[action]=show".

The problem can be solved by adding an additional check before encoding the value.

This is a possible solution (replacement for the line foreach ($params as $k => $v) $params[$k] = $k . '=' . rawurlencode($v);):

foreach ($params as $param => $value) {
    if (!is_array($value)) {
        $params[$param] = $param . '=' . rawurlencode($value);
    } else {
        foreach ($value as $subParam => $subValue) {
            $params[$param] = $param . '[' . $subParam . ']=' . rawurlencode($subValue);
        }
    }
}
mad-develop commented 5 years ago

Confirmed. I'll make a pull request when i have tested these changes. Related: #90

mad-develop commented 5 years ago

Still a warning when having multidim arrays (&my_extension_plugin[filter][name]=something)

This could be a fix. Using GeneralUtility::implodeArrayForUrl.

private static function extractArraysFromParams($params)
{
    // turn array back into query string
    // so it can be used with parse_str
    if (empty($params)) {
        return [];
    }

    $qs = \TYPO3\CMS\Core\Utility\GeneralUtility::implodeArrayForUrl('', $params);
    parse_str($qs, $output);
    return $output;
}