问题
seems like a call to
$this->_redirect('*/*/myaction',$myargs);
does not properly escape the arguments so if
$myargs=array(p1=>'string that has + or / within it')
the created URL will be something like:
..../myaction/?p1/string%20that%20has%20+%20or%20/%20within%20it
causing the getParams collection on the action to have p1 with value 'string that has or ' <- plus sign missing and value broken and ' within it' with no value or something similar.
is there any standard way I should handle the arguments before passing them to _redirect ?
Eyal
回答1:
Yes, there are two standard ways.
Pass all your params as route params, but encode them with php urlencode() func:
foreach ($myargs as $key => $val) { $myargs[$key] = urlencode($val); } $this->_redirect('*/*/myaction', $myargs);
Pass your params as query params
$this->_redirect('*/*/myaction', array('_query', $myargs));
You'd better take second approach, because your params logically are not route but query parameters. Magento is made with a lot of architecture thinking, so it usually points better ways to do stuff - that's why in your case it's easier to send params using second way.
Notice: _redirect() internally uses Mage_Core_Model_Url, so everything said in this answer is true for all other url-forming routines and all usages of Url model.
回答2:
refer to http://www.blooberry.com/indexdot/html/topics/urlencoding.htm#whatwhy and read the section "Reserved characters"
来源:https://stackoverflow.com/questions/4538422/magento-redirect-with-parameters-that-have-or