@@ -64,31 +64,39 @@ public class URLCodec implements BinaryEncoder, BinaryDecoder, StringEncoder, St
6464 * Release 1.5 made this field final.
6565 */
6666 protected static final byte ESCAPE_CHAR = '%' ;
67+
6768 /**
6869 * BitSet of www-form-url safe characters.
70+ * @deprecated Will be removed in 2.0 (CODEC-230)
6971 */
70- protected static final BitSet WWW_FORM_URL = new BitSet (256 );
72+ @ Deprecated
73+ protected static final BitSet WWW_FORM_URL ;
74+
75+ private static final BitSet WWW_FORM_URL_SAFE = new BitSet (256 );
7176
7277 // Static initializer for www_form_url
7378 static {
7479 // alpha characters
7580 for (int i = 'a' ; i <= 'z' ; i ++) {
76- WWW_FORM_URL .set (i );
81+ WWW_FORM_URL_SAFE .set (i );
7782 }
7883 for (int i = 'A' ; i <= 'Z' ; i ++) {
79- WWW_FORM_URL .set (i );
84+ WWW_FORM_URL_SAFE .set (i );
8085 }
8186 // numeric characters
8287 for (int i = '0' ; i <= '9' ; i ++) {
83- WWW_FORM_URL .set (i );
88+ WWW_FORM_URL_SAFE .set (i );
8489 }
8590 // special chars
86- WWW_FORM_URL .set ('-' );
87- WWW_FORM_URL .set ('_' );
88- WWW_FORM_URL .set ('.' );
89- WWW_FORM_URL .set ('*' );
91+ WWW_FORM_URL_SAFE .set ('-' );
92+ WWW_FORM_URL_SAFE .set ('_' );
93+ WWW_FORM_URL_SAFE .set ('.' );
94+ WWW_FORM_URL_SAFE .set ('*' );
9095 // blank to be replaced with +
91- WWW_FORM_URL .set (' ' );
96+ WWW_FORM_URL_SAFE .set (' ' );
97+
98+ // Create a copy in case anyone (ab)uses it
99+ WWW_FORM_URL = (BitSet ) WWW_FORM_URL_SAFE .clone ();
92100 }
93101
94102
@@ -123,7 +131,7 @@ public static final byte[] encodeUrl(BitSet urlsafe, final byte[] bytes) {
123131 return null ;
124132 }
125133 if (urlsafe == null ) {
126- urlsafe = WWW_FORM_URL ;
134+ urlsafe = WWW_FORM_URL_SAFE ;
127135 }
128136
129137 final ByteArrayOutputStream buffer = new ByteArrayOutputStream ();
@@ -191,7 +199,7 @@ public static final byte[] decodeUrl(final byte[] bytes) throws DecoderException
191199 */
192200 @ Override
193201 public byte [] encode (final byte [] bytes ) {
194- return encodeUrl (WWW_FORM_URL , bytes );
202+ return encodeUrl (WWW_FORM_URL_SAFE , bytes );
195203 }
196204
197205
0 commit comments