SPGetQueryString empty querystring &

Jan 18, 2011 at 5:08 PM

Not sure if anyone has encountered this...

if you use SPGetQueryString from a page that's url ends in & it will error out.  An example url is below (from a quick launch or tree view link to a folder in a document library)


That little & at the end causes the SPGetQueryString function to fail during the length check.  Here...

// Get the Query String parameters and their values and return in an array
 $.fn.SPServices.SPGetQueryString = function () {
  var queryStringVals = new Object();
  var qs = location.search.substring(1, location.search.length);
  var args = qs.split("&");
  for (var i = 0;i < args.length;i++) {
   var rxQS = /^([^=]+)=(.*)/i,
   matches = rxQS.exec(args[i]);
   if (rxQS.test(location.href))
   if (matches != null)
   if (matches.length > 2) queryStringVals[matches[1]] = unescape(matches[2]).replace('+', ' ');
  return queryStringVals;
 };// End of function SPGetQueryString

As you can see, as a workaround I added a check to see if the matches is null and that seems to fix the problem.  If there is a better way to fix this, please let me know.

Jan 19, 2011 at 12:05 PM

Thanks for the fix! These edge conditions come up from time to time, and I appreciate a fix rather than simply a report.


Jan 19, 2011 at 12:05 PM
This discussion has been copied to a work item. Click here to go to the work item and continue the discussion.