You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@commons.apache.org by Jim the Standing Bear <st...@gmail.com> on 2008/05/06 06:23:36 UTC

which commons codec converts space to %20?

hello,

I am always under the impression that URL encoding converts spaces to
%20, and only to find out the URLEncoder from both commons-codec and
java converts spaces to "+" signs.

So the question is, which codec converts spaces to %20?  I am working
on a piece of code that allows users to download some files, and if
the spaces in the filenames are converted to "+" signs, then firefox
automatically chops off everything from the first "+" to the end.  So
I would like to convert them to %20 instead, but not sure which code
actually does that.  Thanks.

- Jim

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
For additional commands, e-mail: user-help@commons.apache.org


Re: which commons codec converts space to %20?

Posted by Jim the Standing Bear <st...@gmail.com>.
thanks a million, Henri!

On Thu, May 8, 2008 at 2:27 AM, Henri Yandell <fl...@gmail.com> wrote:
> Cheesy is how we earn our wages :)
>
>  I had a quick play at adding it to Codec. The simplest method seems to
>  me to be to add a subclass, as making it an option on URLCodec doesn't
>  feel very clean due to the bitset being static.
>
>  package org.apache.commons.codec.net;
>
>  import java.util.BitSet;
>
>  public class NoPlusURLCodec extends URLCodec {
>
>     protected BitSet NO_PLUS_WWW_FORM_URL;
>
>     public NoPlusURLCodec() {
>         super();
>         cloneBitSet();
>     }
>
>     public NoPlusURLCodec(String charset) {
>         super(charset);
>         cloneBitSet();
>     }
>
>     private void cloneBitSet() {
>         NO_PLUS_WWW_FORM_URL = WWW_FORM_URL.clone();
>         NO_PLUS_WWW_FORM_URL.clear(' ');
>     }
>
>     public byte[] encode(byte[] bytes) {
>         return encodeUrl(NO_PLUS_WWW_FORM_URL, bytes);
>     }
>
>  }
>
>  Completely untested/uncompiled etc - it looks like removing the space
>  char from the bitset will turn off the feature. Probably not worth the
>  effort of bothering with given you can do the replace.
>
>  Hen
>
>  On Wed, May 7, 2008 at 2:05 PM, Jim the Standing Bear
>
>
> <st...@gmail.com> wrote:
>  > Thanks Henri.  It sounds like what I have to do after all.  I was
>  >  trying to avoid this - not because it is difficult, but just sort of
>  >  cheesy if you know what I mean
>  >
>  >
>  >
>  >
>  >  On Wed, May 7, 2008 at 3:29 PM, Henri Yandell <fl...@gmail.com> wrote:
>  >  > It probably needs to be an option added to the URLEncoder class. I
>  >  >  doubt there's anything that does this for you right now.
>  >  >
>  >  >  For now - I would recommend that you use a search and replace on the
>  >  >  output of URLEncoder to change the + to %20.
>  >  >
>  >  >  Hen
>  >  >
>  >  >
>  >  >
>  >  >  On Mon, May 5, 2008 at 9:23 PM, Jim the Standing Bear
>  >  >  <st...@gmail.com> wrote:
>  >  >  > hello,
>  >  >  >
>  >  >  >  I am always under the impression that URL encoding converts spaces to
>  >  >  >  %20, and only to find out the URLEncoder from both commons-codec and
>  >  >  >  java converts spaces to "+" signs.
>  >  >  >
>  >  >  >  So the question is, which codec converts spaces to %20?  I am working
>  >  >  >  on a piece of code that allows users to download some files, and if
>  >  >  >  the spaces in the filenames are converted to "+" signs, then firefox
>  >  >  >  automatically chops off everything from the first "+" to the end.  So
>  >  >  >  I would like to convert them to %20 instead, but not sure which code
>  >  >  >  actually does that.  Thanks.
>  >  >  >
>  >  >  >  - Jim
>  >  >  >
>  >  >  >  ---------------------------------------------------------------------
>  >  >  >  To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
>  >  >  >  For additional commands, e-mail: user-help@commons.apache.org
>  >  >  >
>  >  >  >
>  >  >
>  >  >  ---------------------------------------------------------------------
>  >  >  To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
>  >  >  For additional commands, e-mail: user-help@commons.apache.org
>  >  >
>  >  >
>  >
>  >
>  >
>  >  --
>  >  --------------------------------------
>  >  Standing Bear Has Spoken
>  >  --------------------------------------
>  >
>  >
>  >
>  >  ---------------------------------------------------------------------
>  >  To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
>  >  For additional commands, e-mail: user-help@commons.apache.org
>  >
>  >
>
>  ---------------------------------------------------------------------
>  To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
>  For additional commands, e-mail: user-help@commons.apache.org
>
>



-- 
--------------------------------------
Standing Bear Has Spoken
--------------------------------------

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
For additional commands, e-mail: user-help@commons.apache.org


Re: which commons codec converts space to %20?

Posted by Henri Yandell <fl...@gmail.com>.
Cheesy is how we earn our wages :)

I had a quick play at adding it to Codec. The simplest method seems to
me to be to add a subclass, as making it an option on URLCodec doesn't
feel very clean due to the bitset being static.

package org.apache.commons.codec.net;

import java.util.BitSet;

public class NoPlusURLCodec extends URLCodec {

    protected BitSet NO_PLUS_WWW_FORM_URL;

    public NoPlusURLCodec() {
        super();
        cloneBitSet();
    }

    public NoPlusURLCodec(String charset) {
        super(charset);
        cloneBitSet();
    }

    private void cloneBitSet() {
        NO_PLUS_WWW_FORM_URL = WWW_FORM_URL.clone();
        NO_PLUS_WWW_FORM_URL.clear(' ');
    }

    public byte[] encode(byte[] bytes) {
        return encodeUrl(NO_PLUS_WWW_FORM_URL, bytes);
    }

}

Completely untested/uncompiled etc - it looks like removing the space
char from the bitset will turn off the feature. Probably not worth the
effort of bothering with given you can do the replace.

Hen

On Wed, May 7, 2008 at 2:05 PM, Jim the Standing Bear
<st...@gmail.com> wrote:
> Thanks Henri.  It sounds like what I have to do after all.  I was
>  trying to avoid this - not because it is difficult, but just sort of
>  cheesy if you know what I mean
>
>
>
>
>  On Wed, May 7, 2008 at 3:29 PM, Henri Yandell <fl...@gmail.com> wrote:
>  > It probably needs to be an option added to the URLEncoder class. I
>  >  doubt there's anything that does this for you right now.
>  >
>  >  For now - I would recommend that you use a search and replace on the
>  >  output of URLEncoder to change the + to %20.
>  >
>  >  Hen
>  >
>  >
>  >
>  >  On Mon, May 5, 2008 at 9:23 PM, Jim the Standing Bear
>  >  <st...@gmail.com> wrote:
>  >  > hello,
>  >  >
>  >  >  I am always under the impression that URL encoding converts spaces to
>  >  >  %20, and only to find out the URLEncoder from both commons-codec and
>  >  >  java converts spaces to "+" signs.
>  >  >
>  >  >  So the question is, which codec converts spaces to %20?  I am working
>  >  >  on a piece of code that allows users to download some files, and if
>  >  >  the spaces in the filenames are converted to "+" signs, then firefox
>  >  >  automatically chops off everything from the first "+" to the end.  So
>  >  >  I would like to convert them to %20 instead, but not sure which code
>  >  >  actually does that.  Thanks.
>  >  >
>  >  >  - Jim
>  >  >
>  >  >  ---------------------------------------------------------------------
>  >  >  To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
>  >  >  For additional commands, e-mail: user-help@commons.apache.org
>  >  >
>  >  >
>  >
>  >  ---------------------------------------------------------------------
>  >  To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
>  >  For additional commands, e-mail: user-help@commons.apache.org
>  >
>  >
>
>
>
>  --
>  --------------------------------------
>  Standing Bear Has Spoken
>  --------------------------------------
>
>
>
>  ---------------------------------------------------------------------
>  To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
>  For additional commands, e-mail: user-help@commons.apache.org
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
For additional commands, e-mail: user-help@commons.apache.org


Re: which commons codec converts space to %20?

Posted by Jim the Standing Bear <st...@gmail.com>.
Thanks Henri.  It sounds like what I have to do after all.  I was
trying to avoid this - not because it is difficult, but just sort of
cheesy if you know what I mean


On Wed, May 7, 2008 at 3:29 PM, Henri Yandell <fl...@gmail.com> wrote:
> It probably needs to be an option added to the URLEncoder class. I
>  doubt there's anything that does this for you right now.
>
>  For now - I would recommend that you use a search and replace on the
>  output of URLEncoder to change the + to %20.
>
>  Hen
>
>
>
>  On Mon, May 5, 2008 at 9:23 PM, Jim the Standing Bear
>  <st...@gmail.com> wrote:
>  > hello,
>  >
>  >  I am always under the impression that URL encoding converts spaces to
>  >  %20, and only to find out the URLEncoder from both commons-codec and
>  >  java converts spaces to "+" signs.
>  >
>  >  So the question is, which codec converts spaces to %20?  I am working
>  >  on a piece of code that allows users to download some files, and if
>  >  the spaces in the filenames are converted to "+" signs, then firefox
>  >  automatically chops off everything from the first "+" to the end.  So
>  >  I would like to convert them to %20 instead, but not sure which code
>  >  actually does that.  Thanks.
>  >
>  >  - Jim
>  >
>  >  ---------------------------------------------------------------------
>  >  To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
>  >  For additional commands, e-mail: user-help@commons.apache.org
>  >
>  >
>
>  ---------------------------------------------------------------------
>  To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
>  For additional commands, e-mail: user-help@commons.apache.org
>
>



-- 
--------------------------------------
Standing Bear Has Spoken
--------------------------------------

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
For additional commands, e-mail: user-help@commons.apache.org


Re: which commons codec converts space to %20?

Posted by Henri Yandell <fl...@gmail.com>.
It probably needs to be an option added to the URLEncoder class. I
doubt there's anything that does this for you right now.

For now - I would recommend that you use a search and replace on the
output of URLEncoder to change the + to %20.

Hen

On Mon, May 5, 2008 at 9:23 PM, Jim the Standing Bear
<st...@gmail.com> wrote:
> hello,
>
>  I am always under the impression that URL encoding converts spaces to
>  %20, and only to find out the URLEncoder from both commons-codec and
>  java converts spaces to "+" signs.
>
>  So the question is, which codec converts spaces to %20?  I am working
>  on a piece of code that allows users to download some files, and if
>  the spaces in the filenames are converted to "+" signs, then firefox
>  automatically chops off everything from the first "+" to the end.  So
>  I would like to convert them to %20 instead, but not sure which code
>  actually does that.  Thanks.
>
>  - Jim
>
>  ---------------------------------------------------------------------
>  To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
>  For additional commands, e-mail: user-help@commons.apache.org
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
For additional commands, e-mail: user-help@commons.apache.org