[BUGFIX] Shortcut redirect ignores linkVars syntax
authorStefan Galinski <stefan.galinski@gmail.com>
Thu, 1 Dec 2011 17:52:15 +0000 (18:52 +0100)
committerTolleiv Nietsch <info@tolleiv.de>
Thu, 9 Feb 2012 07:35:06 +0000 (08:35 +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: I3966eedf284b06b7765f38ca07ea6cd7155babb3
Fixes: #32253
Releases: 4.7, 4.6
Reviewed-on: http://review.typo3.org/7015
Reviewed-by: Björn Pedersen
Reviewed-by: Markus Klein
Tested-by: Markus Klein
Reviewed-by: Stefan Neufeind
Reviewed-by: Wouter Wolters
Reviewed-by: Tolleiv Nietsch
Tested-by: Tolleiv Nietsch
typo3/sysext/cms/tslib/class.tslib_fe.php
typo3/sysext/cms/tslib/class.tslib_pagegen.php

index 528ccd1..855765a 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
                        /** @var $cObj tslib_cObj */
index bfd5874..e53d316 100644 (file)
@@ -138,44 +138,7 @@ class TSpagegen {
                }
 
                        // 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();
 
                        // dtdAllowsFrames indicates whether to use the target attribute in links
                $GLOBALS['TSFE']->dtdAllowsFrames = FALSE;