[GH-ISSUE #87] The query string is built incorrectly when the path contains a parameter #34

Closed
opened 2026-03-16 12:53:18 +03:00 by kerem · 12 comments
Owner

Originally created by @simoncas on GitHub (Aug 28, 2019).
Original GitHub issue: https://github.com/hoppscotch/hoppscotch/issues/87

Originally assigned to: @simoncas, @hosseinnedaee on GitHub.

Describe the bug
The URL is crafted incorrectly when the path already contains a query string and when additional parameters are added through the options.
Example: https://reqres.in/api/users?param1=value1?param2=value2

To Reproduce
Steps to reproduce the behavior:
url: http://whatever.com
path: /whatever?param1=value1
parameters: param2 as Key1 and value2 as Value1
Open the developer tools and select the network tab. Filter requests by XHR
Send the request by hitting the Send button.
Using the developer tools, analyze the HTTP request crafted by postwoman, especially the URL

The URL is https://reqres.in/api/users?param1=value1?param2=value2 which isn't valid. The query string isn't valid since the parameters are preceded twice by a question mark. The second parameter should be preceded by a "&" instead.

Expected behavior
The crafted URL should be https://reqres.in/api/users?param1=value1&param2=value2.
In other words, if the path already contains a query string then the additional parameters specified through the parameter section must be correctly added.

Screenshots
Screenshot from 2019-08-28 18-36-24

Screenshot from 2019-08-28 18-34-09

Originally created by @simoncas on GitHub (Aug 28, 2019). Original GitHub issue: https://github.com/hoppscotch/hoppscotch/issues/87 Originally assigned to: @simoncas, @hosseinnedaee on GitHub. **Describe the bug** The URL is crafted incorrectly when the path already contains a query string and when additional parameters are added through the options. Example: https://reqres.in/api/users?param1=value1?param2=value2 **To Reproduce** Steps to reproduce the behavior: url: http://whatever.com path: /whatever?param1=value1 parameters: _param2_ as Key1 and _value2_ as Value1 Open the developer tools and select the network tab. Filter requests by XHR Send the request by hitting the __Send__ button. Using the developer tools, analyze the HTTP request crafted by postwoman, especially the URL The URL is _https://reqres.in/api/users?param1=value1?param2=value2_ which isn't valid. The query string isn't valid since the parameters are preceded twice by a question mark. The second parameter should be preceded by a "&" instead. **Expected behavior** The crafted URL should be https://reqres.in/api/users?param1=value1&param2=value2. In other words, if the path already contains a query string then the additional parameters specified through the parameter section must be correctly added. **Screenshots** ![Screenshot from 2019-08-28 18-36-24](https://user-images.githubusercontent.com/11412464/63874952-c952dc80-c9c2-11e9-9307-b739a547fe8c.png) ![Screenshot from 2019-08-28 18-34-09](https://user-images.githubusercontent.com/11412464/63874897-afb19500-c9c2-11e9-907b-a60ecd2bcbb7.png)
Author
Owner

@liyasthomas commented on GitHub (Aug 29, 2019):

While we're finding a fix to this issue, I suggest you to separate parameters from request path and use Parameters section to specify required parameters.

<!-- gh-comment-id:526004731 --> @liyasthomas commented on GitHub (Aug 29, 2019): While we're finding a fix to this issue, I suggest you to separate parameters from request `path` and use **Parameters** section to specify required parameters.
Author
Owner

@simoncas commented on GitHub (Aug 29, 2019):

I'm okay to work on this.

They are 2 ways to solve this issue.

First option:
Check with a regex if the query string already contains parameters. Then based on the result, craft correctly the query string. (quick fix)

Second option:
Extract the parameters from the path and automatically fill the parameters sections with the params. (postman style). We must also decide if we should keep in sync (bidirectional) the parameters section and the path. This is how it's implemented by postman. When a change is made whether to the path or to the parameters sections then the change is replicated to the other component.
(sounds more like a feature).

What do you think ?

<!-- gh-comment-id:526085476 --> @simoncas commented on GitHub (Aug 29, 2019): I'm okay to work on this. They are 2 ways to solve this issue. **First option:** Check with a regex if the query string already contains parameters. Then based on the result, craft correctly the query string. **(quick fix)** **Second option:** Extract the parameters from the `path` and automatically fill the **parameters** sections with the params. (postman style). We must also decide if we should keep in sync (bidirectional) the parameters section and the `path`. This is how it's implemented by postman. When a change is made whether to the `path` or to the parameters sections then the change is replicated to the other component. (**sounds more like a feature**). What do you think ?
Author
Owner

@liyasthomas commented on GitHub (Aug 29, 2019):

Second option sounds great! I've assigned this to you. Looking forward on your PR 🙌

<!-- gh-comment-id:526089363 --> @liyasthomas commented on GitHub (Aug 29, 2019): Second option sounds great! I've assigned this to you. Looking forward on your PR :raised_hands:
Author
Owner

@liyasthomas commented on GitHub (Aug 29, 2019):

#62 can also be solved with the second approach of binding key-value pairs to a fast URL entry input box. @NBTX

<!-- gh-comment-id:526137658 --> @liyasthomas commented on GitHub (Aug 29, 2019): #62 can also be solved with the second approach of binding key-value pairs to a fast URL entry input box. @NBTX
Author
Owner

@AndrewBastin commented on GitHub (Aug 30, 2019):

Yoo, I was kinda working on a PR myself for this... My idea to resolve this was on clicking the Send button, the path input is parsed and the values are appended to the params list.

<!-- gh-comment-id:526539173 --> @AndrewBastin commented on GitHub (Aug 30, 2019): Yoo, I was kinda working on a PR myself for this... My idea to resolve this was on clicking the Send button, the path input is parsed and the values are appended to the params list.
Author
Owner

@AndrewBastin commented on GitHub (Sep 12, 2019):

Hi there,

So, I am kinda busy as I am moving to Canada and won't be back on proper coding till like the end of the week, so in the meantime, I am unassigning myself from this issue, anyone interested to tackle this issue please feel to do so.

<!-- gh-comment-id:530860999 --> @AndrewBastin commented on GitHub (Sep 12, 2019): Hi there, So, I am kinda busy as I am moving to Canada and won't be back on proper coding till like the end of the week, so in the meantime, I am unassigning myself from this issue, anyone interested to tackle this issue please feel to do so.
Author
Owner

@hosseinnedaee commented on GitHub (Sep 13, 2019):

Hi,
Can I work on this?
I'd like to solve it with the second approach.

<!-- gh-comment-id:531099157 --> @hosseinnedaee commented on GitHub (Sep 13, 2019): Hi, Can I work on this? I'd like to solve it with the second approach.
Author
Owner

@liyasthomas commented on GitHub (Sep 13, 2019):

@hosseinnedaee you are open to work on this 🎉

<!-- gh-comment-id:531099294 --> @liyasthomas commented on GitHub (Sep 13, 2019): @hosseinnedaee you are open to work on this :tada:
Author
Owner

@hosseinnedaee commented on GitHub (Sep 16, 2019):

Hi
I pushed my changes sync-path-and-parameters
Could you please check the functionality. (I didn't clean the code yet)

<!-- gh-comment-id:531989681 --> @hosseinnedaee commented on GitHub (Sep 16, 2019): Hi I pushed my changes [sync-path-and-parameters](https://github.com/hosseinnedaee/postwoman/tree/sync-path-and-parameters) Could you please check the functionality. (I didn't clean the code yet)
Author
Owner

@liyasthomas commented on GitHub (Sep 16, 2019):

@hosseinnedaee I went through your approach. Seems to be working. Clean your code, optimize the logic. And send PR. I'll run few tests once again.
Btw, thanks for the quick response 🎉

<!-- gh-comment-id:531991870 --> @liyasthomas commented on GitHub (Sep 16, 2019): @hosseinnedaee I went through your approach. Seems to be working. Clean your code, optimize the logic. And send PR. I'll run few tests once again. Btw, thanks for the quick response 🎉
Author
Owner

@hosseinnedaee commented on GitHub (Sep 17, 2019):

@liyasthomas you're welcome
I have submitted a PR #152

<!-- gh-comment-id:532418850 --> @hosseinnedaee commented on GitHub (Sep 17, 2019): @liyasthomas you're welcome I have submitted a PR #152
Author
Owner

@liyasthomas commented on GitHub (Sep 18, 2019):

#152 solves this issue hence closing

<!-- gh-comment-id:532592333 --> @liyasthomas commented on GitHub (Sep 18, 2019): #152 solves this issue hence closing
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/hoppscotch#34
No description provided.