You can't and shouldn't try to prevent special characters from being converted. The correct method is to deliberately encode them before sending the user off, but then decode them before reading the data. If you're using javascript, then you can do this via encodeURIComponent(string)
and decodeURIComponent(string)
.
encodeURIComponent()
will take any string, and convert it into a URL-friendly format.
decodeURIComponent()
will take a converted string, and change it back into a regular format.
As to the reason why you shouldn't try to prevent them from being converted..... I'll quote Mozilla here:
For example, if a user writes "Jack & Jill", using encodeURIComponent the text will get encoded as "Jack %26 Jill". Without encoding, the ampersand could be interpreted on the server as the start of a new field and jeopardize the integrity of the data.
In other words, let's say you allowed symbols in your URL, and someone created a username called "Jack&baseApi=evilURL". Your URL would end up as
http://localhost:4200?username=Jack&baseApi=evilURL&baseApi=https://someOtherService
and I wouldn't want to be in your server's shoes, trying to guess whether the correct baseApi was "evilURL" or "someOtherService".