File tree Expand file tree Collapse file tree 4 files changed +12
-4
lines changed
main/java/org/scribe/utils Expand file tree Collapse file tree 4 files changed +12
-4
lines changed Original file line number Diff line number Diff line change @@ -41,7 +41,7 @@ public static String percentEncode(String string)
4141 Preconditions .checkNotNull (string , "Cannot encode null string" );
4242 try
4343 {
44- return URLEncoder .encode (string , UTF_8 );
44+ return URLEncoder .encode (string , UTF_8 ). replaceAll ( " \\ +" , "%20" ) ;
4545 }
4646 catch (UnsupportedEncodingException uee )
4747 {
Original file line number Diff line number Diff line change @@ -41,4 +41,12 @@ public void shouldThrowExceptionIfRquestHasNoOAuthParameters()
4141 OAuthRequest request = new OAuthRequest (Verb .GET , "http://example.com" );
4242 extractor .extract (request );
4343 }
44+
45+ @ Test
46+ public void shouldProperlyEncodeSpaces ()
47+ {
48+ String expected = "GET&http%3A%2F%2Fexample.com&body%3Dthis%2520param%2520has%2520whitespace%26oauth_callback%3Dhttp%253A%252F%252Fexample%252Fcallback%26oauth_consumer_key%3DAS%2523%2524%255E*%2540%2526%26oauth_signature%3DOAuth-Signature%26oauth_timestamp%3D123456" ;
49+ request .addBodyParameter ("body" , "this param has whitespace" );
50+ assertEquals (expected , extractor .extract (request ));
51+ }
4452}
Original file line number Diff line number Diff line change @@ -52,7 +52,7 @@ public void shouldSetBodyParamsAndHeaders()
5252 postRequest .addBodyParameter ("param" , "value" );
5353 postRequest .addBodyParameter ("param two" , "value with spaces" );
5454 postRequest .send ();
55- assertEquals ("param+two =value+with+spaces ¶m=value" , postRequest .getBodyContents ());
55+ assertEquals ("param%20two =value%20with%20spaces ¶m=value" , postRequest .getBodyContents ());
5656 assertTrue (connection .getHeaders ().containsKey ("Content-Length" ));
5757 }
5858
Original file line number Diff line number Diff line change @@ -23,7 +23,7 @@ public void shouldPercentEncodeMap()
2323 params .put ("key with spaces" , "value with spaces" );
2424 params .put ("&symbols!" , "#!" );
2525
26- String expected = "key=value&key+with+spaces =value+with+spaces &%26symbols%21=%23%21" ;
26+ String expected = "key=value&key%20with%20spaces =value%20with%20spaces &%26symbols%21=%23%21" ;
2727 assertEquals (expected , URLUtils .formURLEncodeMap (params ));
2828 }
2929
@@ -39,7 +39,7 @@ public void shouldReturnEmptyStringForEmptyMap()
3939 public void shouldPercentEncodeString ()
4040 {
4141 String toEncode = "this is a test &^" ;
42- String expected = "this+is+a+test+ %26%5E" ;
42+ String expected = "this%20is%20a%20test%20 %26%5E" ;
4343 assertEquals (expected , URLUtils .percentEncode (toEncode ));
4444 }
4545
You can’t perform that action at this time.
0 commit comments