Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.1k views
in Technique[技术] by (71.8m points)

url encoding - magento _redirect with parameters that have + or /

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

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Yes, there are two standard ways.

  1. 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);

  2. 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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...