[BUGFIX] Shortcut redirect ignores linkVars syntax
authorStefan Galinski <stefan.galinski@gmail.com>
Thu, 1 Dec 2011 17:52:15 +0000 (18:52 +0100)
committerStefan Galinski <stefan.galinski@gmail.com>
Thu, 9 Feb 2012 19:19:25 +0000 (20:19 +0100)
Currently the code that creates the redirect url for a shortcut
page only respects the linkVars option as list of parameters without
additional validation informations like it's documented in the
TSRef. Unfortunatly such paramaters are completely dropped and
this leads to major problems on multilanguage sites with the new
shortcut redirect feature.

Change-Id: I0abcaa56fdeb251c2333f4d807fbef3eeb0299a2
Fixes: #32253
Releases: 4.7, 4.6
Reviewed-on: http://review.typo3.org/8922
Reviewed-by: Stefan Galinski
Tested-by: Stefan Galinski
typo3/sysext/cms/tslib/class.tslib_fe.php
typo3/sysext/cms/tslib/class.tslib_pagegen.php

index a5e60da..6019c5d 100644 (file)
        }
 
        /**
+        * Calculates and sets the internal linkVars based upon the current
+        * $_GET parameters and the setting "config.linkVars".
+        *
+        * @return void
+        */
+       public function calculateLinkVars() {
+               $this->linkVars = '';
+               $linkVars = t3lib_div::trimExplode(',', (string) $this->config['config']['linkVars']);
+               if (empty($linkVars)) {
+                       return;
+               }
+
+               $getData = t3lib_div::_GET();
+               foreach ($linkVars as $linkVar) {
+                       $test = $value = '';
+                       if (preg_match('/^(.*)\((.+)\)$/', $linkVar, $match)) {
+                               $linkVar = trim($match[1]);
+                               $test = trim($match[2]);
+                       }
+
+                       if ($linkVar === '' || !isset($getData[$linkVar])) {
+                               continue;
+                       }
+
+                       if (!is_array($getData[$linkVar])) {
+                               $temp = rawurlencode($getData[$linkVar]);
+
+                               if ($test !== '' && !TSpagegen::isAllowedLinkVarValue($temp, $test)) {
+                                       continue; // Error: This value was not allowed for this key
+                               }
+
+                               $value = '&' . $linkVar . '=' . $temp;
+                       } else {
+                               if ($test !== '' && strcmp('array', $test)) {
+                                       continue; // Error: This key must not be an array!
+                               }
+                               $value = t3lib_div::implodeArrayForUrl($linkVar, $getData[$linkVar]);
+                       }
+
+                       $this->linkVars .= $value;
+               }
+       }
+
+       /**
         * Redirect to target page, if the current page is a Shortcut.
         *
         * If the current page is of type shortcut and accessed directly via its URL, this function redirects to the
         * @return void If page is not a Shortcut, redirects and exits otherwise
         */
        public function checkPageForShortcutRedirect() {
-
                if (!empty($this->originalShortcutPage) && $this->originalShortcutPage['doktype'] == t3lib_pageSelect::DOKTYPE_SHORTCUT) {
-                       $linkVars = t3lib_div::trimExplode(',', (string) $this->config['config']['linkVars']);
-                       if (!empty($linkVars)) {
-                               $getData = t3lib_div::_GET();
-                               foreach ($linkVars as $key) {
-                                       if (isset($getData[$key])) {
-                                               $value = rawurlencode($getData[$key]);
-                                               if (!empty($value)) {
-                                                       $this->linkVars .= '&' . $key . '=' . $value;
-                                               }
-                                       }
-                               }
-                       }
+                       $this->calculateLinkVars();
 
                                // instantiate tslib_content to generate the correct target URL
                        $cObj = t3lib_div::makeInstance('tslib_cObj');
index 3a3fae7..31badc9 100644 (file)
@@ -149,44 +149,7 @@ See <a href="http://wiki.typo3.org/index.php/TYPO3_3.8.1" target="_blank">wiki.t
                }
 
                        // linkVars
-               $linkVars = (string)$GLOBALS['TSFE']->config['config']['linkVars'];
-               if ($linkVars)  {
-                       $linkVarArr = explode(',',$linkVars);
-
-                       $GLOBALS['TSFE']->linkVars='';
-                       $GET = t3lib_div::_GET();
-
-                       foreach ($linkVarArr as $val)   {
-                               $val = trim($val);
-
-                               if (preg_match('/^(.*)\((.+)\)$/',$val,$match)) {
-                                       $val = trim($match[1]);
-                                       $test = trim($match[2]);
-                               } else unset($test);
-
-                               if ($val && isset($GET[$val]))  {
-                                       if (!is_array($GET[$val]))      {
-                                               $tmpVal = rawurlencode($GET[$val]);
-
-                                               if ($test && !TSpagegen::isAllowedLinkVarValue($tmpVal,$test))  {
-                                                       continue;       // Error: This value was not allowed for this key
-                                               }
-
-                                               $value = '&'.$val.'='.$tmpVal;
-                                       } else {
-                                               if ($test && strcmp('array',$test))     {
-                                                       continue;       // Error: This key must not be an array!
-                                               }
-                                               $value = t3lib_div::implodeArrayForUrl($val,$GET[$val]);
-                                       }
-                               } else continue;
-
-                               $GLOBALS['TSFE']->linkVars.= $value;
-                       }
-                       unset($GET);
-               } else {
-                       $GLOBALS['TSFE']->linkVars='';
-               }
+               $GLOBALS['TSFE']->calculateLinkVars();
 
                if($GLOBALS['TSFE']->config['config']['doctype'] == 'html_5') {
                        $GLOBALS['TSFE']->logDeprecatedTyposcript('config.doctype = html_5', 'It will be removed in TYPO3 4.7. Use html5 instead.');