ERROR URIError: URI malformed

Hello,
I am using ionic version 5.4.1 with angular. I have created a basic ionic blank project and try call the application using the follwing URL:

http://localhost:8100/home?errorMessage=Login+ou+senha+do+usu�rio+�+inv�lido

The error message was encoded as you can see, however it is important to realize that it wasn’t encoded using window.encodeURIComponent.

Ionic tries to decode the URL using window.decodeURIComponent, as I could figure out in the following code:

It is an error that happens before calling my component. I created a angular project without Ionic and it works fine.

Could it be a bug ?

Ps: Unfortunately I can’t change the encode method. It is the an error message comming from an api.

Thanks for any help
Regards
Ricardo Moura

It seems that you’ve identified the issue pretty clearly, so:

How do we get from “the API” to “that URL”? If there’s any of your code in that process, that’s where I would work on fixing this (by converting what you are being given by the API, which appears to be ISO-8859-1, into Unicode). If that’s not possible, then I would try to pass this error text via another mechanism that doesn’t go through Ionic’s Config.

I can’t think of any other sensible thing to do on Ionic’s part. Given no other mechanism for declaring encoding, UTF-8 seems to me the only reasonable choice.

So, in summary, I would work to get these API return values into Unicode as soon as possible, so that none of the rest of your app has to worry about unusual character encoding.

Hello,
thanks for you reply.

As a matter of fact it is not a API exactly. It is part of an authentication proccess. It works with redirects like SAML. So it is the URL that brings the user back to my application after an authentication error.

My suspicius regarding to a bug is based on the fact it works in a common angular application without using ionic.

Rergards
Ricardo Moura

For those who is suffering because the same problem… that is a workaround…

Put these lines of code in the main.ts file

let baseUrl = ${window.location.protocol}//${window.location.host}${window.location.pathname};
let search = new URLSearchParams(window.location.search);

//console.log("search: "+ search.toString());

let urlToGo = search.toString().length > 0?baseUrl+’?’+search.toString():baseUrl;

//console.log("urlToGo: "+ urlToGo);
window.history.pushState(null, window.document.title, urlToGo);

platformBrowserDynamic().bootstrapModule(AppModule)
.catch(err => console.log(err));

Regards
Ricardo Moura