@@ -16,7 +16,7 @@ public void shouldPercentEncodeMap()
16
16
params .put ("key with spaces" , "value with spaces" );
17
17
params .put ("&symbols!" , "#!" );
18
18
19
- String expected = "key=value&key%20with%20spaces =value%20with%20spaces &%26symbols%21=%23%21" ;
19
+ String expected = "key=value&key+with+spaces =value+with+spaces &%26symbols%21=%23%21" ;
20
20
assertEquals (expected , URLUtils .formURLEncodeMap (params ));
21
21
}
22
22
@@ -28,6 +28,17 @@ public void shouldReturnEmptyStringForEmptyMap()
28
28
assertEquals (expected , URLUtils .formURLEncodeMap (params ));
29
29
}
30
30
31
+ @ Test
32
+ public void shouldFormURLEncodeMapWithMissingValues ()
33
+ {
34
+ Map <String , String > params = new LinkedHashMap <String , String >();
35
+ params .put ("key" , "value" );
36
+ params .put ("key with spaces" , null );
37
+
38
+ String expected = "key=value&key+with+spaces" ;
39
+ assertEquals (expected , URLUtils .formURLEncodeMap (params ));
40
+ }
41
+
31
42
@ Test
32
43
public void shouldPercentEncodeString ()
33
44
{
@@ -37,24 +48,32 @@ public void shouldPercentEncodeString()
37
48
}
38
49
39
50
@ Test
40
- public void shouldPercentDecodeString ()
51
+ public void shouldFormURLEncodeString ()
52
+ {
53
+ String toEncode = "this is a test &^" ;
54
+ String expected = "this+is+a+test+%26%5E" ;
55
+ assertEquals (expected , URLUtils .formURLEncode (toEncode ));
56
+ }
57
+
58
+ @ Test
59
+ public void shouldFormURLDecodeString ()
41
60
{
42
61
String toDecode = "this+is+a+test+%26%5E" ;
43
62
String expected = "this is a test &^" ;
44
- assertEquals (expected , URLUtils .percentDecode (toDecode ));
63
+ assertEquals (expected , URLUtils .formURLDecode (toDecode ));
45
64
}
46
65
47
66
@ Test
48
- public void shouldEncodeAllSpecialCharacters ()
67
+ public void shouldPercentEncodeAllSpecialCharacters ()
49
68
{
50
69
String plain = "!*'();:@&=+$,/?#[]" ;
51
70
String encoded = "%21%2A%27%28%29%3B%3A%40%26%3D%2B%24%2C%2F%3F%23%5B%5D" ;
52
71
assertEquals (encoded , URLUtils .percentEncode (plain ));
53
- assertEquals (plain , URLUtils .percentDecode (encoded ));
72
+ assertEquals (plain , URLUtils .formURLDecode (encoded ));
54
73
}
55
74
56
75
@ Test
57
- public void shouldNotEncodeReservedCharacters ()
76
+ public void shouldNotPercentEncodeReservedCharacters ()
58
77
{
59
78
String plain = "abcde123456-._~" ;
60
79
String encoded = plain ;
@@ -79,7 +98,7 @@ public void shouldThrowExceptionIfStringToEncodeIsNull()
79
98
public void shouldThrowExceptionIfStringToDecodeIsNull ()
80
99
{
81
100
String toDecode = null ;
82
- URLUtils .percentDecode (toDecode );
101
+ URLUtils .formURLDecode (toDecode );
83
102
}
84
103
85
104
@ Test (expected = IllegalArgumentException .class )
@@ -103,7 +122,7 @@ public void shouldAppendNothingToQuerystringIfGivenEmptyMap()
103
122
public void shouldAppendParametersToSimpleUrl ()
104
123
{
105
124
String url = "http://www.example.com" ;
106
- String expectedUrl = "http://www.example.com?param1=value1¶m2=value%20with%20spaces " ;
125
+ String expectedUrl = "http://www.example.com?param1=value1¶m2=value+with+spaces " ;
107
126
108
127
Map <String , String > params = new HashMap <String , String >();
109
128
params .put ("param1" , "value1" );
@@ -117,7 +136,7 @@ public void shouldAppendParametersToSimpleUrl()
117
136
public void shouldAppendParametersToUrlWithQuerystring ()
118
137
{
119
138
String url = "http://www.example.com?already=present" ;
120
- String expectedUrl = "http://www.example.com?already=present¶m1=value1¶m2=value%20with%20spaces " ;
139
+ String expectedUrl = "http://www.example.com?already=present¶m1=value1¶m2=value+with+spaces " ;
121
140
122
141
Map <String , String > params = new HashMap <String , String >();
123
142
params .put ("param1" , "value1" );
@@ -128,7 +147,7 @@ public void shouldAppendParametersToUrlWithQuerystring()
128
147
}
129
148
130
149
@ Test
131
- public void shouldEncodePlusSymbol ()
150
+ public void shouldPercentEncodePlusSymbol ()
132
151
{
133
152
String plain = "7aEP+jNAwvjc0mjhqg0nuXPf" ;
134
153
String encoded = "7aEP%2BjNAwvjc0mjhqg0nuXPf" ;
@@ -137,11 +156,11 @@ public void shouldEncodePlusSymbol()
137
156
}
138
157
139
158
@ Test
140
- public void shouldDecodePlusSymbol ()
159
+ public void shouldURLDecodePlusSymbol ()
141
160
{
142
161
String encoded = "oauth_verifier=7aEP%2BjNAwvjc0mjhqg0nuXPf" ;
143
162
String expected = "oauth_verifier=7aEP+jNAwvjc0mjhqg0nuXPf" ;
144
163
145
- Assert .assertEquals (expected , URLUtils .percentDecode (encoded ));
164
+ Assert .assertEquals (expected , URLUtils .formURLDecode (encoded ));
146
165
}
147
166
}
0 commit comments