You are viewing a plain text version of this content. The canonical link for it is here.
Posted to modperl@perl.apache.org by John Reid <jr...@cix.co.uk> on 2000/10/05 12:53:49 UTC

Apache::Request and parameters = 0

Hi guys

Has anyone any experience of passing a 0 as a parameter value through
Apache::Request. I am passing a QUERY_STRING like
?param1=value1&param2=0&param3=value3. It appears that the 0 is being
interpretted as an empty string. Is this a bug/expected behaviour or am
I looking in completely the wrong area for the source of the problem?

-- 
John Reid
Senior Analyst/Programmer
Open Connect (Ireland) Ltd
http://www.openconnect.ie/

Re: Apache::Request and parameters = 0

Posted by John Reid <jr...@cix.co.uk>.
Matt Sergeant wrote:
> 
> On Thu, 5 Oct 2000, Dana C. Chandler III wrote:
> 
> > In my limited experience, it is Perl in general that treats the value 0,
> > in a query string as the empty string.  In all of the scripts I have
> > written, if 0 is possible as a param value, I have to explicity check
> > for 0.
> 
> This is only the case when you're going:
> 
> if ($r->param('name')) {
>         # do something
> }
> 
> if its a zero then you should expect to be bitten in the ass by that
> one. However I do assume that there's similar code going on somewhere to
> turn the zero into undef.
> 

Just to add, I was explicitly checking for 0 in the value returned but
was getting an empty string. 0 in this case was a single character
required. An empty string was not.

Once Matt informed me it was a bug/feature it set my mind at ease and I
was able to implement a work around.

-- 
John Reid
Senior Analyst/Programmer
Open Connect (Ireland) Ltd
http://www.openconnect.ie/

Re: Apache::Request and parameters = 0

Posted by Matt Sergeant <ma...@sergeant.org>.
On Thu, 5 Oct 2000, Dana C. Chandler III wrote:

> Yes, in particular,
> 
> $value = $r->param('name') || "";

Or worse, $r->param('name') || "3"; # default but true

Even I'm guilty of that one sometimes :-)

-- 
<Matt/>

** Director and CTO **
**  AxKit.com Ltd   **  ** XML Application Serving **
** http://axkit.org **  ** XSLT, XPathScript, XSP  **
**     Personal Web Site: http://sergeant.org/     **


Re: Apache::Request and parameters = 0

Posted by "Dana C. Chandler III" <dc...@bellatlantic.net>.
Matt Sergeant wrote:
> 
> On Thu, 5 Oct 2000, Dana C. Chandler III wrote:
> 
> > In my limited experience, it is Perl in general that treats the value 0,
> > in a query string as the empty string.  In all of the scripts I have
> > written, if 0 is possible as a param value, I have to explicity check
> > for 0.
> 
> This is only the case when you're going:
> 
> if ($r->param('name')) {
>         # do something
> }
> 
> if its a zero then you should expect to be bitten in the ass by that
> one. However I do assume that there's similar code going on somewhere to
> turn the zero into undef.
> 
> --
> <Matt/>
> 
> ** Director and CTO **
> **  AxKit.com Ltd   **  ** XML Application Serving **
> ** http://axkit.org **  ** XSLT, XPathScript, XSP  **
> **     Personal Web Site: http://sergeant.org/     **

Yes, in particular,

$value = $r->param('name') || "";

this little snipit of code will bite you if the param is 0.

I should have been more specific.

--Dana

Re: Apache::Request and parameters = 0

Posted by Matt Sergeant <ma...@sergeant.org>.
On Thu, 5 Oct 2000, Dana C. Chandler III wrote:

> In my limited experience, it is Perl in general that treats the value 0,
> in a query string as the empty string.  In all of the scripts I have
> written, if 0 is possible as a param value, I have to explicity check
> for 0.  

This is only the case when you're going:

if ($r->param('name')) {
	# do something
}

if its a zero then you should expect to be bitten in the ass by that
one. However I do assume that there's similar code going on somewhere to
turn the zero into undef.

-- 
<Matt/>

** Director and CTO **
**  AxKit.com Ltd   **  ** XML Application Serving **
** http://axkit.org **  ** XSLT, XPathScript, XSP  **
**     Personal Web Site: http://sergeant.org/     **


Re: Apache::Request and parameters = 0

Posted by "Dana C. Chandler III" <dc...@bellatlantic.net>.
Matt Sergeant wrote:
> 
> On Thu, 5 Oct 2000, John Reid wrote:
> 
> > Hi guys
> >
> > Has anyone any experience of passing a 0 as a parameter value through
> > Apache::Request. I am passing a QUERY_STRING like
> > ?param1=value1&param2=0&param3=value3. It appears that the 0 is being
> > interpretted as an empty string. Is this a bug/expected behaviour or am
> > I looking in completely the wrong area for the source of the problem?
> 
> No its a bug. It also occurs if the QUERY_STRING is just 0 on its own.
> 
> --
> <Matt/>
> 
> ** Director and CTO **
> **  AxKit.com Ltd   **  ** XML Application Serving **
> ** http://axkit.org **  ** XSLT, XPathScript, XSP  **
> **     Personal Web Site: http://sergeant.org/     **

In my limited experience, it is Perl in general that treats the value 0,
in a query string as the empty string.  In all of the scripts I have
written, if 0 is possible as a param value, I have to explicity check
for 0.  

In essence I agree with Matt, but wanted to pop that little piece of
information in there in case it turns out to be pertinent...

--Dana

Re: Apache::Request and parameters = 0

Posted by Matt Sergeant <ma...@sergeant.org>.
On Thu, 5 Oct 2000, John Reid wrote:

> Hi guys
> 
> Has anyone any experience of passing a 0 as a parameter value through
> Apache::Request. I am passing a QUERY_STRING like
> ?param1=value1&param2=0&param3=value3. It appears that the 0 is being
> interpretted as an empty string. Is this a bug/expected behaviour or am
> I looking in completely the wrong area for the source of the problem?

No its a bug. It also occurs if the QUERY_STRING is just 0 on its own.

-- 
<Matt/>

** Director and CTO **
**  AxKit.com Ltd   **  ** XML Application Serving **
** http://axkit.org **  ** XSLT, XPathScript, XSP  **
**     Personal Web Site: http://sergeant.org/     **