[SWFObject] Bug in getQueryParamValue() function. Please fix ASAP.

Geoff Stearns geoff at deconcept.com
Wed May 31 08:40:08 PDT 2006


just checked it in, have a look:

http://svn.deconcept.com/swfobject/trunk/


On May 31, 2006, at 11:29 AM, Geoff Stearns wrote:

> nice catch - i like your compact version better than my fix for it,  
> so if you don't mind i'll roll it into the next version:
>
> deconcept.util = {
> 	getRequestParameter: function(param) {
> 		var q = document.location.search || document.location.hash;
> 		if(q) {
> 			var pairs = q.substring(1).split("&");
> 			for (var i=0; i < pairs.length; i++) {
> 				if (pairs[i].substring(0, pairs[i].indexOf("=")) == param) {
> 					return pairs[i].substring((pairs[i].indexOf("=")+1));
> 				}
> 			}
> 		}
> 		return "";
> 	}
> }
>
> i'm going to check this into the svn repository in a few mins, i  
> have a couple other things to test first.
>
>
>
> On May 31, 2006, at 12:17 AM, Aran Rhee wrote:
>
>> Geoff.
>>
>> I believe I have found a bug in your query params function with  
>> swfObject. The way you are returning values from your search means  
>> that it will return the value of the 1st parameter which contains  
>> the substring of the name passed into getQueryParamValue(), not  
>> necessarily the actual value you want!
>>
>> e.g.
>>
>> somepage.html?myEmailName=aaaa at aaaa.com&Email=xxxx at xxxx.com
>>
>> getQueryParamValue('Email');
>>
>> will actually return aaaa at aaaa.com, as the value as "Email" was  
>> found in the 1st param name string.
>>
>>
>> I think you need to actually split the params into an array and do  
>> a full text match. I wrote the below as a fix for myself quickly,  
>> and itdesigned to be readable, not compact, but you get the idea.
>>
>>  function getRequestParameter (key)
>>  {
>>   var q = document.location.search || document.location.hash;
>>   if(q)
>>   {
>>    var qArray = q.substring(1).split("&");
>>    var len = qArray.length;
>>    for (i = 0; i<len; i++)
>>    {
>>     var pair = qArray[i];
>>     var splitIndex = pair.indexOf("=");
>>     var paramName = pair.substring(0, splitIndex);
>>     var paramValue= pair.substring((splitIndex+1));
>>     if (paramName == key)
>>     {
>>      return paramValue;
>>     }
>>    }
>>    return "";
>>   }
>>   return "";
>>  }
>>
>>
>> You could compact it like:
>>
>> function getRequestParameter (key) {
>>   var q = document.location.search || document.location.hash;
>>   if(q) {
>>    var qArray = q.substring(1).split("&");
>>    for (i = 0; i<qArray.length; i++) {
>>     if (qArray[i].substring(0, qArray[i].indexOf("=")) == key)  
>> return qArray[i].substring((qArray[i].indexOf("=")+1));
>>    }
>>    return "";
>>   }
>>   return "";
>>  }
>>
>>
>>
>>
>> Cheers,
>>
>> Aran
>> _______________________________________________
>> SWFObject mailing list
>> SWFObject at lists.deconcept.com
>> http://lists.deconcept.com/listinfo.cgi/swfobject-deconcept.com
>
> _______________________________________________
> SWFObject mailing list
> SWFObject at lists.deconcept.com
> http://lists.deconcept.com/listinfo.cgi/swfobject-deconcept.com

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.deconcept.com/pipermail/swfobject-deconcept.com/attachments/20060531/999bf66d/attachment-0005.htm>


More information about the Swfobject mailing list