Skip to content

Commit b36e82f

Browse files
authored
Fixed NPE in OAuth1 implementation when one of the parameters has no value (#1877)
1 parent b7328f9 commit b36e82f

File tree

2 files changed

+18
-0
lines changed

2 files changed

+18
-0
lines changed

client/src/main/java/org/asynchttpclient/oauth/OAuthSignatureCalculatorInstance.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,9 @@ private String encodedParams(ConsumerKey consumerAuth, RequestToken userAuth, lo
156156
}
157157

158158
private static String percentEncodeAlreadyFormUrlEncoded(String s) {
159+
if (s == null) {
160+
return "";
161+
}
159162
s = STAR_CHAR_PATTERN.matcher(s).replaceAll("%2A");
160163
s = PLUS_CHAR_PATTERN.matcher(s).replaceAll("%20");
161164
s = ENCODED_TILDE_PATTERN.matcher(s).replaceAll("~");

client/src/test/java/org/asynchttpclient/oauth/OAuthSignatureCalculatorTest.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
import org.asynchttpclient.Request;
2121
import org.asynchttpclient.RequestBuilder;
2222
import org.asynchttpclient.util.Utf8UrlEncoder;
23+
import org.junit.jupiter.api.Test;
2324

2425
import java.io.UnsupportedEncodingException;
2526
import java.net.URLDecoder;
@@ -132,6 +133,20 @@ public void testSignatureBaseStringWithRawUri() throws NoSuchAlgorithmException
132133
testSignatureBaseStringWithEncodableOAuthToken(request);
133134
}
134135

136+
@Test
137+
public void testSignatureBaseStringWithNoValueQueryParameter() throws NoSuchAlgorithmException {
138+
// Query parameter with no value in OAuth1 should be treated the same as query parameter with an empty value.
139+
// i.e."http://example.com/request?b5" == "http://example.com/request?b5="
140+
// Tested with http://lti.tools/oauth/
141+
Request request = post("http://example.com/request?b5=%3D%253D&a3=a&c%40&a2=r%20b")
142+
.addFormParam("c2", "")
143+
.addFormParam("a3", "2 q")
144+
.build();
145+
146+
testSignatureBaseString(request);
147+
testSignatureBaseStringWithEncodableOAuthToken(request);
148+
}
149+
135150
// based on the reference test case from
136151
// http://oauth.pbwiki.com/TestCases
137152
@RepeatedIfExceptionsTest(repeats = 5)

0 commit comments

Comments
 (0)