[SWFObject] Bug in getQueryParamValue() function. Slight fix ?

Aran Rhee aran.rhee at qdc.net.au
Wed May 31 19:20:25 PDT 2006


Geoff.
 
Yep, My bad. I was remembering an earlier incarnation on my machine which
had a full if/else block, so I did have a 3rd return in there. It then got
ditched it when I was looking at compacting/optimising the code. Been a long
day.... :)
 
Cheers,
 
Aran


  _____  

From: swfobject-bounces at lists.deconcept.com
[mailto:swfobject-bounces at lists.deconcept.com] On Behalf Of Geoff Stearns
Sent: Thursday, 1 June 2006 11:48 AM
To: swfobject at lists.deconcept.com
Subject: Re: [SWFObject] Bug in getQueryParamValue() function. Slight fix ?


it will still return "" if it doesn't find anything... 

the extra return was redundant as it will just do nothing once the loop is
done.

you can test this by going to my test page and putting this in the address
bar:

javascript:alert(getQueryParamValue("test"));


here's the test page url:
http://dev.deconcept.com/1.4.2_test/swfobject.html




you'll see it alert an empty string.







On May 31, 2006, at 8:23 PM, Aran Rhee wrote:


Geoff.

Great. One thing though. I think we still need to have an empty string
return if it loops through all the pairs and doesn't find a match. The one
return you have at present returns an empty string only if there is no query
string found at all. ( need 3 returns in total as below) 

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 matched key value
return pairs[i].substring((pairs[i].indexOf("=")+1));
}
}
// empty string if no match found
return "";
}
// empty string if no querystring at all
return "";
}
}


Cheers,

Aran





  _____  

From: swfobject-bounces at lists.deconcept.com
[mailto:swfobject-bounces at lists.deconcept.com] On Behalf Of Geoff Stearns
Sent: Thursday, 1 June 2006 1:40 AM
To: swfobject at lists.deconcept.com
Subject: Re: [SWFObject] Bug in getQueryParamValue() function. Please
fixASAP.


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
<mailto:somepage.html?myEmailName=aaaa at aaaa.com&Email=xxxx at xxxx.com> 

getQueryParamValue('Email');

will actually return  <mailto:aaaa at aaaa.com> 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


_______________________________________________
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/20060601/89aba7b6/attachment-0005.htm>


More information about the Swfobject mailing list