bruno: [Bug] - URLEncode edited Query parameters from the dedicated table/tab on change

I imported requests a while ago now, and some were imported with query parameters like dates:

?from=2023-10-23T00%3A00%3A00%2B00%3A00&to=2023-10-23T23%3A59%3A59%2B00%3A00

They work fine when I run them. The Query tab allows me to see what the current decoded values are (nice for human eyes! ❤️). image

But when I modify my “from” date, by example starting a day earlier, in the Value field of the Query tab, then the URL is immediately altered, and the query params are no longer encoded - making my request fail, and me losing the previously encoded value that was running fine before 😞

?from=2023-10-22T00:00:00+00:00&to=2023-10-23T23:59:59+00:00

I can ctrl-z to get back to it, and manually fix it, but altering the encoded value itself in the main URL can sometimes be tedious. And we are not far from having something a nice user experience here - my suggestion : when editing any value within the “Query” tab, automatically apply URLEncode while updating the resulting URL.

About this issue

  • Original URL
  • State: open
  • Created 3 years ago
  • Reactions: 13
  • Comments: 16 (4 by maintainers)

Most upvoted comments

One checkbox per line is definitely too much, I was thinking about putting a checkbox under the right side of the table.

I think it’s best if we have an option to encode parameters.

I’m working with partner API’s that do not decode the parameters on their site. So http://partner.com/api/report?date=2023-10-23T00%3A00%3A00%2B00%3A00 would fail, but http://partner.com/api/report?date=2023-10-23T00:00:00+00:00 works even through both URL are basically the same.

This was one thing that bugged me with Insomnia, because it would automatically encode all query parameters, without an option to disable it.

After reviewing the related issues, I believe the root cause of many of them is an inconsistency in how Bruno handles URL encoding between the below two components

  • URL Input Box
  • Query Parameters Table

Currently, Bruno automatically decodes the URL from the input field using URLSearchParams. However, when changes are made in the query parameters table, those changes are not encoded before updating the URL in the input field. This inconsistency leads to confusion and creates a number of edge cases.

Another challenge is that we cannot determine whether the URL entered in the input field is already encoded. Given this uncertainty, it is not ideal for Bruno to assume the URL is encoded and then proceed with decoding while populating the query parameters table.

Solution To resolve this, we are considering the following approach:

  1. Bruno will not perform any encoding or decoding in the UI. The URL input field and the query parameters table will remain identical.
  2. At the time of sending the request, Bruno will encode the query parameters using JavaScript’s encodeURIComponent function. This will be the default behavior, but users will have the option to disable encoding via a setting if needed.

Tradeoff: With the current implementation, when users input an encoded URL, Bruno decodes it before displaying it, making it easier to read. With the new approach, encoded URLs will remain as entered, which may reduce readability in some cases. Ex: ?from=2023-10-23T00%3A00%3A00%2B00%3A00&to=2023-10-23T23%3A59%3A59%2B00%3A00

Hi, this is what I worked on

https://github.com/usebruno/bruno/assets/61945879/0a38a6e9-1a46-4487-90fb-60912fb28a35

I’ve already made the pr if someone wants to test it

@joaoduarte19 We need some time to investigate a proper solution for this. I will be able to give you some update in 2 weeks.

@Kwaadpepper As commented here https://github.com/usebruno/bruno/issues/732#issuecomment-1775923313 a checkbox per line seems too much

Do you have cases where you’d want to encode some params, but not others ?

Temporary workaround using this “script > pre-request” line

req.setUrl(req.getUrl().replace(/(.+?\?).+/,'$1') + encodeURIComponent(req.getUrl().replace(/.+?\?/,'')));

EDIT : I just noticed that it can break calls - not a good solution

For the one test I need, “ugly fixed” by using… req.setUrl(req.getUrl().replace(/(.+?\?).+/,'$1') + encodeURIComponent(req.getUrl().replace(/.+?\?/,'')) .replaceAll('%2F', '/').replaceAll('%26', '&').replaceAll('%3D', '=') );