diff --git a/ballerina-tests/http-dispatching-tests/tests/query_params_binding_test.bal b/ballerina-tests/http-dispatching-tests/tests/query_params_binding_test.bal index 56b6e50884..949d2799b4 100644 --- a/ballerina-tests/http-dispatching-tests/tests/query_params_binding_test.bal +++ b/ballerina-tests/http-dispatching-tests/tests/query_params_binding_test.bal @@ -230,3 +230,9 @@ function testQueryParamBindingCase16() returns error? { [map, string[]] resPayload = check resourceQueryParamBindingClient->/query/case16(query1 = string`{"name":"John"%2C "age":37}`, query2 = strVals); test:assertEquals(resPayload, [{"name":"John", "age":37}, strVals]); } + +@test:Config {} +function testNoQueryParamBindingCase19() returns error? { + map resPayload = check resourceQueryParamBindingClient->/query/case19; + test:assertEquals(resPayload, {}); +} diff --git a/ballerina-tests/http-dispatching-tests/tests/resource_params_binding_test_common.bal b/ballerina-tests/http-dispatching-tests/tests/resource_params_binding_test_common.bal index 33ec045e0d..5c13ed02e2 100644 --- a/ballerina-tests/http-dispatching-tests/tests/resource_params_binding_test_common.bal +++ b/ballerina-tests/http-dispatching-tests/tests/resource_params_binding_test_common.bal @@ -223,6 +223,10 @@ service /query on resourceParamBindingListener { resource function get case16(map query1, string[] query2) returns [map, string[]] { return [query1, query2]; } + + resource function get case19(http:Request req) returns map { + return req.getQueryParams(); + } } service /header on resourceParamBindingListener { diff --git a/changelog.md b/changelog.md index 7dd633ff9a..54d659c691 100644 --- a/changelog.md +++ b/changelog.md @@ -5,6 +5,12 @@ This file contains all the notable changes done to the Ballerina HTTP package th The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +## Unreleased + +### Fixed + +- [Fix returning an empty query param even without any query params in the request](https://github.com/ballerina-platform/ballerina-standard-library/issues/4705) + ## [2.9.1] - 2023-08-08 ### Fixed diff --git a/native/src/main/java/io/ballerina/stdlib/http/api/HttpDispatcher.java b/native/src/main/java/io/ballerina/stdlib/http/api/HttpDispatcher.java index b176006112..282c61c678 100644 --- a/native/src/main/java/io/ballerina/stdlib/http/api/HttpDispatcher.java +++ b/native/src/main/java/io/ballerina/stdlib/http/api/HttpDispatcher.java @@ -56,7 +56,6 @@ import static io.ballerina.stdlib.http.api.HttpConstants.AUTHORIZATION_HEADER; import static io.ballerina.stdlib.http.api.HttpConstants.BEARER_AUTHORIZATION_HEADER; import static io.ballerina.stdlib.http.api.HttpConstants.DEFAULT_HOST; -import static io.ballerina.stdlib.http.api.HttpConstants.EMPTY; import static io.ballerina.stdlib.http.api.HttpConstants.JWT_DECODER_CLASS_NAME; import static io.ballerina.stdlib.http.api.HttpConstants.JWT_DECODE_METHOD_NAME; import static io.ballerina.stdlib.http.api.HttpConstants.JWT_INFORMATION; @@ -197,7 +196,7 @@ private static String[] extractRawPathAndQuery(String uriWithoutMatrixParams) { String[] rawPathAndQuery = new String[2]; String[] splittedUri = uriWithoutMatrixParams.split(QUERY_STRING_SEPARATOR); rawPathAndQuery[0] = splittedUri[0]; - rawPathAndQuery[1] = splittedUri.length > 1 ? splittedUri[1] : EMPTY; + rawPathAndQuery[1] = splittedUri.length > 1 ? splittedUri[1] : null; return rawPathAndQuery; }