Skip to content

Commit 50c35bc

Browse files
Changed whitespace encoding to %21 instead of '+'
Changed version number for release
1 parent 8c8f26e commit 50c35bc

File tree

4 files changed

+12
-4
lines changed

4 files changed

+12
-4
lines changed

src/main/java/org/scribe/utils/URLUtils.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff 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
{

src/test/java/org/scribe/extractors/BaseStringExtractorTest.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff 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
}

src/test/java/org/scribe/model/RequestTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff 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&param=value", postRequest.getBodyContents());
55+
assertEquals("param%20two=value%20with%20spaces&param=value", postRequest.getBodyContents());
5656
assertTrue(connection.getHeaders().containsKey("Content-Length"));
5757
}
5858

src/test/java/org/scribe/utils/URLUtilsTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff 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

0 commit comments

Comments
 (0)