question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

GET request to API with % as part of query, URI malformed error is thrown

See original GitHub issue

Current behavior:

When a GET request is made to API with % as part of query, URI malformed error is thrown. For eg, GET request to /api/query?tag=10%

Works on Chrome browser:

But not when Cypress test is run:

Desired behavior:

API call with % should be decoded correctly and should behave as on Chrome.

I am not entirely sure if issues 2372 and 5274 are relevant to this.

Test code to reproduce

I have created a repository here for the steps to be reproduced. express app to serve static html file and handle API request

Versions

Cypress: ^5.0.0 Chrome: Version 84.0.4147.125 (Official Build) (64-bit) OS: macOS Mojave Version 10.14.2

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:12 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
eugeneoeicommented, Sep 18, 2020

@sinharaksh1t i made the changes according to your suggestion and ran the test case again. you are right!! URI malformed error is no longer thrown after encoding the query params.

And now it made me realised I actually should be using encodeURIComponent in all the API calls involving query params on the URL made from the front-end application I’m working on. Currently, the API I did “decodes” by running a regex which will no longer be needed if encodeURIComponent is used on the front-end application. Thanks for the tip!

I guess this is technically not a bug and can be closed? what do you think @jennifer-shehane ?

1reaction
sinharaksh1tcommented, Sep 17, 2020

@eugeneoei since we know that Cypress is calling JavaScript’s decodeURIComponent on the URL, have you tried encoding the query parameters in the URL before making the call? Not sure if this will help, but in the codebase of where I work, we use JavaScript’s encodeURIComponent for some API calls where we need to specifically append query params on the URL.

Below is an example from your own example repo to demonstrate what I mean:

axios.get(`/api/query?tag=${encodeURIComponent(10%)}`)
					.then(function (response) {
						...do something
					})
					.catch(function (error) {
						...do something else after catch
					})
Read more comments on GitHub >

github_iconTop Results From Across the Web

URIError: malformed URI sequence - MDN Web Docs - Mozilla
The JavaScript exception "malformed URI sequence" occurs when URI encoding or decoding wasn't successful.
Read more >
Why do I keep getting "Missing/Malformed URL Parameters ...
I'm trying to do a POST request in C#, using RestSharp, in Visual Studio 2022. I tested the API using Postman, which was...
Read more >
"Malformed URL" string when trying to inject SQL
In HTTP(S) the server sees the authority part on the Host: header and the path and query parts in the (GET / POST)...
Read more >
cURL error 3 url malformed : How we fix it - Bobcares
The error usually occurs due to incorrect URL usage or version mismatch between cURL and the underlying application. At Bobcares, we often get...
Read more >
The uri is invalid error when I make a httpCallout
You can try verifying the endpoint by adding a system debug in the same code to see the final request string. Then try...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found