GET request to API with % as part of query, URI malformed error is thrown
See original GitHub issueCurrent 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:
- Created 3 years ago
- Comments:12 (3 by maintainers)
Top 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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@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 ifencodeURIComponent
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 ?
@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’sencodeURIComponent
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: