Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Brought percent-encoding of spaces into line with OAuth spec section 3.6

  • Loading branch information...
commit 541a29e5117db22276566d38409ca1c2c96d49c9 1 parent 871733d
@eboto eboto authored
View
7 src/main/java/org/scribe/encoders/URL.java
@@ -27,9 +27,11 @@
public class URL {
private static final String UTF8 = "UTF-8";
+ private static final String URL_SPACE_ENCODING = "+";
+ private static final String OAUTH_SPEC_SPACE_ENCODING = "%20";
/**
- * URLencode a given string
+ * Encode a given string as specified in OAuth Spec section 3.6.
*
* @param string to encode
* @return encoded string
@@ -37,7 +39,8 @@
*/
public static String percentEncode(String string){
try{
- return URLEncoder.encode(string,UTF8);
+ return URLEncoder.encode(string,UTF8)
+ .replace(URL_SPACE_ENCODING, OAUTH_SPEC_SPACE_ENCODING);
}catch(UnsupportedEncodingException uee){
throw new RuntimeException("Wrong encoding: " + UTF8);
}
View
2  src/test/java/org/scribe/oauth/OAuthParametersTest.java
@@ -42,7 +42,7 @@ public void shouldSetupDefaultParams(){
public void shouldReturnEncodedParams(){
params.put("q","foo");
params.put("other param", "bar");
- String encodedString = "oauth_consumer_key=any&oauth_nonce=827ccb0eea8a706c4c34a16891f84e7b&oauth_signature_method=HMAC-SHA1&oauth_timestamp=12345&oauth_version=1.0&other+param=bar&q=foo";
+ String encodedString = "oauth_consumer_key=any&oauth_nonce=827ccb0eea8a706c4c34a16891f84e7b&oauth_signature_method=HMAC-SHA1&oauth_timestamp=12345&oauth_version=1.0&other%20param=bar&q=foo";
assertEquals(encodedString, params.asSortedFormEncodedString());
}
Please sign in to comment.
Something went wrong with that request. Please try again.