You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by hstang <hu...@mxnmedia.com> on 2007/06/06 19:07:41 UTC

Encoding issue: + versus %20

I am currently having problems loading an image in Tomcat 6.13.  I have a
file "a b.jpg" in upload folder and I want to have a link to go to it.

<pre>

(1) [a href="upload/a+b.jpg">Here[/a]
(2) [a href="upload/a%20b.jpg">Here[/a]

</pre>

Why does (2) work and not (1)?  Both '+' and "%20" represents spaces so
there's no reason why they can't work. The Java URLEncoder.encode() will
output (1), and my current framework of choice also output (1) but I can't
seem to come out with (1).  What libraries can you use to force (2) out? 
What's the problem?

-- 
View this message in context: http://www.nabble.com/Encoding-issue%3A-%2B-versus--20-tf3879033.html#a10992518
Sent from the Tomcat - User mailing list archive at Nabble.com.


---------------------------------------------------------------------
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: Encoding issue: + versus %20

Posted by Bill Barker <wb...@wilshire.com>.
"hstang" <hu...@mxnmedia.com> wrote in message 
news:10999556.post@talk.nabble.com...
>
> Does that mean there's no way to load images with file names that contains
> spaces then?  I'm not understanding something here.  Because if i include 
> a
> link to a graphic image whose filename contains spaces, it uses +, and
> tomcat refuses to the load image; however if I replace it with %20, then 
> it
> works.  How could this be?
>

Because, as Lucas has stated below, the '+' character only translates to ' ' 
when it is part of the query-string.  The only valid way to get a ' ' 
encoded before the query-string is to use %20.  Which is why you should save 
a lot of hair-pulling, and only allow filenames without spaces :).

>
> Lucas Galfaso wrote:
>>
>> Short answer:
>>   An URL has many part, one part that is called "path" (in this case
>> "upload/a b.jpg") and another part is called "query" (that is usually
>> what is after the "?" in a URL) These two parts use slightly different
>> reserved characters that may, should, or must be escaped under
>> different rules. To use "+" as a space is correct within the query,
>> but is correct within the path.
>>
>> Long answer:
>> http://www.ietf.org/rfc/rfc2396.txt
>> 2.2. Reserved Characters
>> 2.3. Unreserved Characters
>> 2.4. Escape Sequences
>> 3.3. Path Component
>> 3.4. Query Component
>>
>> Regards,
>>   LG
>>
>> On 6/6/07, hstang <hu...@mxnmedia.com> wrote:
>>>
>>> I am currently having problems loading an image in Tomcat 6.13.  I have 
>>> a
>>> file "a b.jpg" in upload folder and I want to have a link to go to it.
>>>
>>> (1)  upload/a+b.jpg Here
>>> (2)  upload/a%20b.jpg Here
>>>
>>> Why does (2) work and not (1)?  Both '+' and "%20" represents spaces so
>>> there's no reason why they can't work. The Java URLEncoder.encode() will
>>> output (1), and my current framework of choice also output (1) but I
>>> can't
>>> seem to come out with (1).  What libraries can you use to force (2) out?
>>> What's the problem?
>>>
>>> --
>>> View this message in context:
>>> http://www.nabble.com/Encoding-issue%3A-%2B-versus--20-tf3879033.html#a10992518
>>> Sent from the Tomcat - User mailing list archive at Nabble.com.
>>>
>>>
>>> ---------------------------------------------------------------------
>>> 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
>>>
>>>
>>
>> ---------------------------------------------------------------------
>> 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
>>
>>
>>
>
> -- 
> View this message in context: 
> http://www.nabble.com/Encoding-issue%3A-%2B-versus--20-tf3879033.html#a10999556
> Sent from the Tomcat - User mailing list archive at Nabble.com.
>
>
> ---------------------------------------------------------------------
> 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
>
> 




---------------------------------------------------------------------
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: Encoding issue: + versus %20

Posted by hstang <hu...@mxnmedia.com>.
Does that mean there's no way to load images with file names that contains
spaces then?  I'm not understanding something here.  Because if i include a
link to a graphic image whose filename contains spaces, it uses +, and
tomcat refuses to the load image; however if I replace it with %20, then it
works.  How could this be?


Lucas Galfaso wrote:
> 
> Short answer:
>   An URL has many part, one part that is called "path" (in this case
> "upload/a b.jpg") and another part is called "query" (that is usually
> what is after the "?" in a URL) These two parts use slightly different
> reserved characters that may, should, or must be escaped under
> different rules. To use "+" as a space is correct within the query,
> but is correct within the path.
> 
> Long answer:
> http://www.ietf.org/rfc/rfc2396.txt
> 2.2. Reserved Characters
> 2.3. Unreserved Characters
> 2.4. Escape Sequences
> 3.3. Path Component
> 3.4. Query Component
> 
> Regards,
>   LG
> 
> On 6/6/07, hstang <hu...@mxnmedia.com> wrote:
>>
>> I am currently having problems loading an image in Tomcat 6.13.  I have a
>> file "a b.jpg" in upload folder and I want to have a link to go to it.
>>
>> (1)  upload/a+b.jpg Here
>> (2)  upload/a%20b.jpg Here
>>
>> Why does (2) work and not (1)?  Both '+' and "%20" represents spaces so
>> there's no reason why they can't work. The Java URLEncoder.encode() will
>> output (1), and my current framework of choice also output (1) but I
>> can't
>> seem to come out with (1).  What libraries can you use to force (2) out?
>> What's the problem?
>>
>> --
>> View this message in context:
>> http://www.nabble.com/Encoding-issue%3A-%2B-versus--20-tf3879033.html#a10992518
>> Sent from the Tomcat - User mailing list archive at Nabble.com.
>>
>>
>> ---------------------------------------------------------------------
>> 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
>>
>>
> 
> ---------------------------------------------------------------------
> 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
> 
> 
> 

-- 
View this message in context: http://www.nabble.com/Encoding-issue%3A-%2B-versus--20-tf3879033.html#a10999556
Sent from the Tomcat - User mailing list archive at Nabble.com.


---------------------------------------------------------------------
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: Encoding issue: + versus %20

Posted by Lucas Galfaso <lg...@gmail.com>.
Mmmm..
It should read:
To use "+" as a space is correct within the query, but is not correct
within the path.

- LG

On 6/7/07, Christopher Schultz <ch...@christopherschultz.net> wrote:
> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
>
> Lucas,
>
> > To use "+" as a space is correct within the query, but is correct
> > within the path.
>
> Huh?
>
> - -chris
>
> -----BEGIN PGP SIGNATURE-----
> Version: GnuPG v1.4.7 (MingW32)
> Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org
>
> iD8DBQFGaBz59CaO5/Lv0PARAsAyAKCuBTmf55ChCLReV9E9tFgiw73Q4ACfRvaw
> Crj7D4JkxYKtbs1XbJuj9Js=
> =sBah
> -----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
>
>

---------------------------------------------------------------------
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: Encoding issue: + versus %20

Posted by "Caldarale, Charles R" <Ch...@unisys.com>.
> From: Christopher Schultz [mailto:chris@christopherschultz.net] 
> Subject: Re: Encoding issue: + versus %20
> 
> > To use "+" as a space is correct within the query, but is correct
> > within the path.
> 
> Huh?

I think a rather critical "not" was left out of the second part of the
sentence.

 - Chuck


THIS COMMUNICATION MAY CONTAIN CONFIDENTIAL AND/OR OTHERWISE PROPRIETARY
MATERIAL and is thus for use only by the intended recipient. If you
received this in error, please contact the sender and delete the e-mail
and its attachments from all computers.

---------------------------------------------------------------------
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: Encoding issue: + versus %20

Posted by Christopher Schultz <ch...@christopherschultz.net>.
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Lucas,

> To use "+" as a space is correct within the query, but is correct
> within the path.

Huh?

- -chris

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.7 (MingW32)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iD8DBQFGaBz59CaO5/Lv0PARAsAyAKCuBTmf55ChCLReV9E9tFgiw73Q4ACfRvaw
Crj7D4JkxYKtbs1XbJuj9Js=
=sBah
-----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: Encoding issue: + versus %20

Posted by Lucas Galfaso <lg...@gmail.com>.
Short answer:
  An URL has many part, one part that is called "path" (in this case
"upload/a b.jpg") and another part is called "query" (that is usually
what is after the "?" in a URL) These two parts use slightly different
reserved characters that may, should, or must be escaped under
different rules. To use "+" as a space is correct within the query,
but is correct within the path.

Long answer:
http://www.ietf.org/rfc/rfc2396.txt
2.2. Reserved Characters
2.3. Unreserved Characters
2.4. Escape Sequences
3.3. Path Component
3.4. Query Component

Regards,
  LG

On 6/6/07, hstang <hu...@mxnmedia.com> wrote:
>
> I am currently having problems loading an image in Tomcat 6.13.  I have a
> file "a b.jpg" in upload folder and I want to have a link to go to it.
>
> (1)  upload/a+b.jpg Here
> (2)  upload/a%20b.jpg Here
>
> Why does (2) work and not (1)?  Both '+' and "%20" represents spaces so
> there's no reason why they can't work. The Java URLEncoder.encode() will
> output (1), and my current framework of choice also output (1) but I can't
> seem to come out with (1).  What libraries can you use to force (2) out?
> What's the problem?
>
> --
> View this message in context: http://www.nabble.com/Encoding-issue%3A-%2B-versus--20-tf3879033.html#a10992518
> Sent from the Tomcat - User mailing list archive at Nabble.com.
>
>
> ---------------------------------------------------------------------
> 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
>
>

---------------------------------------------------------------------
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