Skip to content

Commit ca30fae

Browse files
committed
CODEC-230 URLCodec.WWW_FORM_URL should be private
git-svn-id: https://svn.apache.org/repos/asf/commons/proper/codec/trunk@1788761 13f79535-47bb-0310-9956-ffa450edef68
1 parent 5d3142a commit ca30fae

2 files changed

Lines changed: 20 additions & 11 deletions

File tree

src/changes/changes.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ The <action> type attribute can be add,update,fix,remove.
4545
<release version="1.11" date="2017-MM-DD" description="Feature and fix release.">
4646
<!-- The first attribute below should be the issue id; makes it easier to navigate in the IDE outline -->
4747

48+
<action issue="CODEC-230" dev="sebb" type="fix">URLCodec.WWW_FORM_URL should be private</action>
4849
<action issue="CODEC-229" dev="sebb" type="fix">StringUtils.newStringxxx(null) should return null, not NPE</action>
4950
<action issue="CODEC-220" dev="sebb" type="add">Fluent interface for DigestUtils</action>
5051
<action issue="CODEC-222" dev="sebb" type="add">Fluent interface for HmacUtils</action>

src/main/java/org/apache/commons/codec/net/URLCodec.java

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)