Issue with URL Parameters not decoding during Test Methods

Typing the URL into the browser with the following params:


NOT During a test method executing the line:


Debugs the following value:


However the following code DURING A Test Method

PageReference pr = Page.Respond_Invite;    pr.getParameters().put('rec','atWAzwsBvm3hyWrApj4mBo0BsaasxAmfySPTrXZxNVbdPIMHXr1FfVg2Fhoa%2B7FY');

Debugs the following:


Any ideas why the getParameters decodes the URL Param when a test method is not running and does not decode it when a test method is running?

In order to successfully execute the test I have to add do this:


There is no code in-between just the debug…


The decoding of URL parameter


is done by the browser in which the request is run and the decoded param is passed to the underlying controller(in our case its apex controller).

But in the case of test, when you set the URL parameter, there won’t be any browser to decode that parameter and send it to its underlying controller. So the apex controller receives the URL parameter as such available.

So its the developer’s responsibility to test with proper URL encoding and decoding.

Hope it helps.

Source : Link , Question Author : Eric , Answer Author : Vigneshwaran G

Leave a Comment