Extra ? in QueryString coming back from Twitter

Apr 20, 2011 at 7:55 PM


I entered this a little bit ago as an Issue but it seems to have not gotten any traction so I'm repeating here (especially since it happened again today).

I'm using ASP.NET MVC with your library, and anytime I have a GET Action that during the action performs the OAuth with Twitter, the URL coming back from Twitter has an extra "?" at the beginning of the QueryString in which case ASP.NET MVC complains saying the required values for the Action Method are not available.  But they are contained in the returned QueryString because its a GET, only it cannot see them because of the extra "?".

My current work arounds are either to store the values in Session and set a different return path for Twitter to follow or to use a Form POST which is much uglier client code.

Any help would be great.



Apr 20, 2011 at 8:47 PM

I found the problem, it's in OAuthTwitter.FilterRequestParameters(Uri fullUrl).

Need to change the lines

string url = fullUrl.ToString().Split('?')[0];
string urlParams = fullUrl.Query;

to something like

var urlParts = fullUrl.ToString().Split('?');
string url = urlParts[0];
string urlParams = urlParts.Length > 1 ? urlParts[1] : null;

because Uri.Query includes the "?" at the beginning so that urlParams is ending up with it as the first character and then it never gets cleaned in the LINQ filter query because this becomes the first char of the first arg.
Also, if (in the old case) the first arg started with "oauth_", then it would not be filtered because it would start with "?oauth_".
Then in the return statement

return url + (filteredParams == string.Empty ? string.Empty : "?" + filteredParams);

another "?" is added to the beginning of the QueryString - which you cannot remove this add because the first argument may be cleared during the LINQ filter query (if the logic worked as expected).

Apr 20, 2011 at 9:12 PM

Thank you very much.  Sometimes I get super busy and really appreciate things like this. :)


Apr 27, 2011 at 4:30 PM
This discussion has been copied to a work item. Click here to go to the work item and continue the discussion.
May 1, 2011 at 3:36 AM

Thanks for the code.  Until I've done a release, you can find the fix here: http://bit.ly/iocV7X.