I have written an Service Provider implementation for OAuth and one of the Devs found a bug in the way the implementation was ordering query parameters. I totally missed the lexicographical ordering requirement in the OAuth spec and was just doing a basic string sort on the name value parameters
Given the following URI request from the consumer:
http://api.com/v1/People/Search?searchfor=fl&[email protected]&Include=addresses
The resulting signature base should order the parameters as:
Include=addresses, [email protected], searchfor=fl
Given the following URI request from the consumer:
http://api.com/v1/People/Search?searchfor=fl&[email protected]&include=addresses
The resulting signature base should order the parameters as:
[email protected], include=addresses, searchfor=fl
Note the case difference in the querystring parameter "include". From what I understand, lexicographical byte value ordering will order parameters using the ascii value and then order asc.
Since I = 73 and i = 105, the capital I should be ordered before the lowercase i.
I have the following so far:
IEnumerable<QueryParameter> queryParameters = parameters
.OrderBy(parm => parm.Key)
.ThenBy(parm => parm.Value)
.Select(
parm => new QueryParameter(parm.Key, UrlEncode(parm.Value)));
But that will not cover the ascii character by character sort (IncLude=test&Include=test will not sort properly).
Any thoughts on how to make an efficient algorithm that will answer this problem? Or how to make the sort case sensitive via ICompare?