You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by "Mark H. Wood" <mw...@IUPUI.Edu> on 2008/06/04 22:09:07 UTC
Does HTTPRequest.getParameter() return encoded or decoded?
If there's a better place to ask, please direct me.
I'm tracking down a problem with third-party code which looks more and
more like double URI-decoding. But I can't find anywhere in the
servlet documentation where it says whether getParameter returns
decoded or encoded data.
???
--
Mark H. Wood, Lead System Programmer mwood@IUPUI.Edu
Typically when a software vendor says that a product is "intuitive" he
means the exact opposite.
Re: Does HTTPRequest.getParameter() return encoded or decoded?
Posted by Bill Barker <wb...@wilshire.com>.
If you are using an older version of mod_jk, the default settings would
double-decode.
"Mark H. Wood" <mw...@IUPUI.Edu> wrote in message
news:20080604200907.GA18063@IUPUI.Edu...
---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org
Re: Does HTTPRequest.getParameter() return encoded or decoded?
Posted by Christopher Schultz <ch...@christopherschultz.net>.
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
Mark,
Mark H. Wood wrote:
| Sorry, I didn't fully specify the problem. I do refer to
| URI-(en|de)coding, not to character encoding issues.
If the original URL was "http://server/app?foo=a%20space" (or even
"http://server/app?foo=a+space", then calling
request.getParameter("foo") will return "a space" (i.e. no percents).
If you have a double-encoded parameter value (say, because you were
trying to pass a URL as a parameter value), then it will not be
double-decoded for you. Thus, "http://server/app?foo=a%3720space", then
getParameter("foo") will return "a%20space".
- -chris
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.9 (MingW32)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org
iEYEARECAAYFAkhO3lcACgkQ9CaO5/Lv0PDfdQCfWsw1squNTM//UNvoeP7icF36
b9IAoKjLoRjTkYT8de5+c3X/ceWXv7Tj
=8PFj
-----END PGP SIGNATURE-----
---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org
Re: Does HTTPRequest.getParameter() return encoded or decoded?
Posted by David Smith <dn...@cornell.edu>.
Correct. With regard to URI encoded GET requests, what you get from
request.getParameter() is already decoded for %nn character encoding
among others. No need to decode it again.
--David
Mark H. Wood wrote:
>Sorry, I didn't fully specify the problem. I do refer to
>URI-(en|de)coding, not to character encoding issues.
>
>So, if I've understood the answers I've seen so far, the value
>returned by getParameter() should *not* be subjected to URI-decoding,
>because it has already been URI-decoded and doing so again would lead to
>trouble with a parameter value which, before URI-encoding, contained a
>percent character.
>
>I'm debugging code we got from elsewhere which URI-decodes stuff it
>got from getParameter(), and as I am not very familiar with the code
>in question and am only a beginner in working with servlet code myself
>I want to be very sure there is not a good reason for these calls. I
>think now I'm sure enough to take them out. Thanks!
>
>
>
---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org
Re: Does HTTPRequest.getParameter() return encoded or decoded?
Posted by "Mark H. Wood" <mw...@IUPUI.Edu>.
Sorry, I didn't fully specify the problem. I do refer to
URI-(en|de)coding, not to character encoding issues.
So, if I've understood the answers I've seen so far, the value
returned by getParameter() should *not* be subjected to URI-decoding,
because it has already been URI-decoded and doing so again would lead to
trouble with a parameter value which, before URI-encoding, contained a
percent character.
I'm debugging code we got from elsewhere which URI-decodes stuff it
got from getParameter(), and as I am not very familiar with the code
in question and am only a beginner in working with servlet code myself
I want to be very sure there is not a good reason for these calls. I
think now I'm sure enough to take them out. Thanks!
--
Mark H. Wood, Lead System Programmer mwood@IUPUI.Edu
Typically when a software vendor says that a product is "intuitive" he
means the exact opposite.
Re: Does HTTPRequest.getParameter() return encoded or decoded?
Posted by David Smith <dn...@cornell.edu>.
The terms encoded and decoded need further definition. If you are
referring to a GET request and parameters in the URL, the answer is
decoded. All the %27s and the like are decoded to their character
equivalent. URLs themselves are ASCII character sets per RFC 1738 (at
least that's what HTML 4.0.1 cites).
If you are referring to internationalization and character set encoding
in POST requests, SRV.4.9 of the servlet spec (I'm reading servlet spec
2.4 here) describes how the servlet container is to deal with it. If
the browser actually sent character encoding information in the
Content-Type header, that encoding is used and the encoding is provided
by request.getCharacterEncoding(). If no character set encoding is
provided, the default ISO-8859-1 encoding is used and
request.getCharacterEncoding() returns null.
--David
Mark H. Wood wrote:
> If there's a better place to ask, please direct me.
>
> I'm tracking down a problem with third-party code which looks more and
> more like double URI-decoding. But I can't find anywhere in the
> servlet documentation where it says whether getParameter returns
> decoded or encoded data.
>
> ???
>
>
---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org
Re: Does HTTPRequest.getParameter() return encoded or decoded?
Posted by Martin <mg...@hotmail.com>.
ApplicationHttpRequest does return encoded
here is why..
package org.apache.catalina.core;
class ApplicationHttpRequest extends HttpServletRequestWrapper
{
public String getParameter(String name)
{
parseParameters();
..which calls...
/** Parses the parameters of this request. If parameters are present in
both the query string and the request content, they are merged. */
void parseParameters()
{
if (parsedParams)
{
return;
}
parameters = new HashMap();
parameters = copyMap(getRequest().getParameterMap());
mergeParameters();
.. which calls...
private void mergeParameters()
{
if ((queryParamString == null) || (queryParamString.length() < 1))
return;
HashMap queryParameters = new HashMap();
String encoding = getCharacterEncoding();
if (encoding == null)
encoding = "ISO-8859-1";
try {
RequestUtil.parseParameters
(queryParameters, queryParamString, encoding);
} catch (Exception e) {
;
}
Iterator keys = parameters.keySet().iterator();
while (keys.hasNext()) {
String key = (String) keys.next();
Object value = queryParameters.get(key);
if (value == null) {
queryParameters.put(key, parameters.get(key));
continue;
}
queryParameters.put
(key, mergeValues(value, parameters.get(key)));
}
parameters = queryParameters;
}
HTH
Martin--
----- Original Message -----
From: "Mark H. Wood" <mw...@IUPUI.Edu>
To: <us...@tomcat.apache.org>
Sent: Wednesday, June 04, 2008 4:09 PM
Subject: Does HTTPRequest.getParameter() return encoded or decoded?
---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org