Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug]: Query parameters are getting parsed #7481

Closed
chathuranga95 opened this issue Dec 19, 2024 · 3 comments
Closed

[Bug]: Query parameters are getting parsed #7481

chathuranga95 opened this issue Dec 19, 2024 · 3 comments
Labels
module/http Reason/Invalid Issue is invalid. Team/PCM Protocol connector packages related issues Team/StandardLibs Type/Bug

Comments

@chathuranga95
Copy link

chathuranga95 commented Dec 19, 2024

Description

When a http service is created with ballerina, the query params accepted to the resource functions are getting parsed when they have delimiters.

Steps to Reproduce

Run the following code with ballerina 2201.5.5 and issue the same request. Observe that the service is logging the query param as the first item in the comma-separated string.

Expected behaviour: The ballerina service should accept the query params as they are.
Code

import ballerina/log;
import ballerina/http;

service / on new http:Listener(9091) {
    resource function get greeting(string q) returns string {
        log:printInfo(q);
        return "Hello, World!";
    }
}

Request

curl --location 'localhost:9091/greeting?q=1%2C2'

Log output

time = 2024-12-19T14:46:05.119+05:30 level = INFO module = chathurangas/multi_server_debugger message = "1"

Affected Version(s)

No response

OS, DB, other environment details and versions

No response

Related area

-> Standard Library

Related issue(s) (optional)

No response

Suggested label(s) (optional)

No response

Suggested assignee(s) (optional)

No response

@NipunaRanasinghe NipunaRanasinghe transferred this issue from ballerina-platform/ballerina-lang Dec 19, 2024
@NipunaRanasinghe
Copy link
Contributor

@chathuranga95 if this a customer related issue, could you please create an issue in the https://github.com/wso2-enterprise/internal-support-ballerina/ repo? That will help us to prioratize the issue

@ballerina-platform ballerina-platform deleted a comment from github-actions bot Dec 20, 2024
@TharmiganK TharmiganK added module/http Team/PCM Protocol connector packages related issues labels Dec 20, 2024
@TharmiganK
Copy link
Contributor

TharmiganK commented Dec 20, 2024

Tested the same code in Ballerina version - 2201.5.5 and latest http package version - 2.8.9, and it is working as expected for the mentioned cURL request(note that the value is a encoded string of value 1,2):

$ curl --location 'localhost:9091/greeting?q=1%2C2'
Hello, World!

Receiving the following log:

$ bal run     
Compiling source
        tharmigan/test:0.1.0

Running executable

time = 2024-12-20T09:44:17.220+05:30 level = INFO module = tharmigan/test message = "1,2"

The values you get after binding to a Ballerina type is the decoded value, not the raw value. If you want the raw value you need to get it from request raw path.

import ballerina/log;
import ballerina/http;

service / on new http:Listener(9091) {
    resource function get greeting(string q, http:Request req) returns string {
        log:printInfo(req.rawPath); // /greeting?q=1%2C2
        log:printInfo(q);
        return "Hello, World!";
    }
}

@TharmiganK TharmiganK added the Reason/Invalid Issue is invalid. label Dec 20, 2024
@TharmiganK
Copy link
Contributor

Closing this issue since it is not reproducible with the latest version

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
module/http Reason/Invalid Issue is invalid. Team/PCM Protocol connector packages related issues Team/StandardLibs Type/Bug
Projects
None yet
Development

No branches or pull requests

4 participants