Skip to content

Commit

Permalink
Fixed RD-10865: Http.Get crashing if passed null key/value in args or…
Browse files Browse the repository at this point in the history
… headers (#409)
  • Loading branch information
bgaidioz authored Apr 25, 2024
1 parent ef34555 commit 9863f44
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,24 @@ trait HttpPackageTest extends CompilerTestContext with DropboxTestCreds with Bef
}
)

val returnBodyCtx = server.createContext(
server.createContext(
"/return-args",
(exchange: HttpExchange) => {
logger.debug(s"/return-args Received request: $exchange")
val response = exchange.getRequestURI.getQuery
val os = exchange.getResponseBody
try {
if (response != null) {
exchange.sendResponseHeaders(200, response.length)
os.write(response.getBytes)
} else {
exchange.sendResponseHeaders(200, 0)
}
} finally os.close()
}
)

private val returnBodyCtx = server.createContext(
"/return-body",
(exchange: HttpExchange) => {
logger.debug(s"/return-body Received request: $exchange")
Expand All @@ -102,7 +119,7 @@ trait HttpPackageTest extends CompilerTestContext with DropboxTestCreds with Bef
logger.info(s"Starting server at address: ${server.getAddress}")
server.start()

def address = server.getAddress
def address: InetSocketAddress = server.getAddress

def stop(): Unit = {
server.stop(0)
Expand Down Expand Up @@ -399,4 +416,40 @@ trait HttpPackageTest extends CompilerTestContext with DropboxTestCreds with Bef
| "http://localhost:$testPort/csv",
| bodyBinary = Binary.FromString("a|b|c\\n1|2|3\\n4|5|6")
|))""".stripMargin)(it => it should evaluateTo("""[{a: 1, b: 2, c: 3}, {a: 4, b: 5, c: 6}]"""))

test(s"""String.Read(Http.Get(
| "http://localhost:$testPort/return-args",
| args=[{"a", "12"}, {"b", "13"}])
|)
|""".stripMargin)(_ should evaluateTo("\"a=12&b=13\""))

test(s"""String.Read(Http.Get(
| "http://localhost:$testPort/return-args",
| args=[{"a", "12"}, {"b", null}, {"c", "14"}])
|)
|""".stripMargin)(_ should evaluateTo("\"a=12&c=14\""))

test(s"""String.Read(Http.Get(
| "http://localhost:$testPort/return-args",
| args=[{null, "12"}, {null, "14"}])
|)
|""".stripMargin)(_ should evaluateTo("\"\""))

test(s"""String.Read(Http.Get(
| "http://localhost:$testPort/return-headers",
| headers=[{"a", "12"}])
|)
|""".stripMargin)(_ should evaluateTo("\"A:12\""))

test(s"""String.Read(Http.Get(
| "http://localhost:$testPort/return-headers",
| headers=[{"a", "12"}, {"b", null}])
|)
|""".stripMargin)(_ should evaluateTo("\"A:12\""))

test(s"""String.Read(Http.Get(
| "http://localhost:$testPort/return-headers",
| headers=[{null, "12"}, {"b", null}])
|)
|""".stripMargin)(_ should evaluateTo("\"\""))
}
Original file line number Diff line number Diff line change
Expand Up @@ -179,13 +179,13 @@ abstract class HttpCallEntry(method: String) extends EntryExtension {
ParamDoc(
"args",
TypeDoc(List("list")),
"The query parameters arguments for the HTTP request. Parameters are URL-encoded automatically.",
"The query parameters arguments for the HTTP request. Parameters are URL-encoded automatically. Any key/value pair with a null key or value will be omitted and won't be included in the URL parameters.",
isOptional = true
),
ParamDoc(
"headers",
TypeDoc(List("list")),
"The HTTP headers to include in the request.",
"The HTTP headers to include in the request. Any key/value pair with a null key or value will be omitted and won't be included in the request headers.",
isOptional = true
),
ParamDoc("expectedStatus", TypeDoc(List("list")), "The list of expected statuses.", isOptional = true)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,9 @@ private LocationSettingValue buildLocationSettingValue(
Object keys = interops.getMembers(record);
Object key = interops.readMember(record, (String) interops.readArrayElement(keys, 0));
Object val = interops.readMember(record, (String) interops.readArrayElement(keys, 1));
vec = vec.$plus$eq(Tuple2.apply((String) key, (String) val));
// ignore entries where key or val is null
if (key != NullObject.INSTANCE && val != NullObject.INSTANCE)
vec = vec.$plus$eq(Tuple2.apply((String) key, (String) val));
}
return new LocationKVSetting(vec.result());
} else if (TypeGuards.isBinaryKind(type)) {
Expand Down

0 comments on commit 9863f44

Please sign in to comment.