How can I use uppercase in URL in svelte-kit? - sveltekit

Uppercase letters automatically convert into lowercase in the URL.
I want the URL will like
"http://127.0.0.1:5173/about#dataprivacy"
But when I hit this URL it changes in
"http://127.0.0.1:5173/about#dataprivacy"

Related

React.js - Avoid automatically decoding HTML entities

My react app seems to be automatically decoding %25 to a %, however I need it to stay as %25.
Let's say I have a route that looks like the below. The route has a param which is a string containing an encoded url.
https://mywebsite.com/{encoded_url_string}
As an example, let's say the unencoded url string is:
https://urlparam.com/public/?test=c%3Dvalue
Which, encoded, would become
https%3A%2F%2Furlparam.com%2Fpublic%2F%3Ftest%3Dc%253Dvalue
So the full route would look like this:
https://mywebsite.com/https%3A%2F%2Furlparam.com%2Fpublic%2F%3Ftest%3Dc%253Dvalue
My issue is that when I grab this param (using the query-string library) from the URL, and try to write it to my page, instead of literally being:
https%3A%2F%2Furlparam.com%2Fpublic%2F%3Ftest%3Dc%253Dvalue
Which is exactly as it is in the URL param, I'm getting:
https%3A%2F%2Furlparam.com%2Fpublic%2F%3Ftest%3Dc%3Dvalue
Notice that the last bit in the first one is "test%3Dc %25 3Dvalue" (ignore the spaces, StackOverflow won't let me bold without it), while the second one is just test%3Dc%3Dvalue (missing the %25)
Any ideas why the %25 is being decoded to a simple %? Any way to prevent that?

How to store strings with whitespaces to databases and retrieve them for URL?

I have Shops stored in a Postgreql database, I retrieve them from the frontend and use them as a link. However, since there is whitespace in them the URL looks like this /New%20Shop. I don't know what the right solution is, I can trim the string on the frontend link part but that can result in me not being able to query search the shop since there is whitespace at the database part. I can also change the database so that it holds the strings with whitespace with an underscore and replace the underscores with whitespace on the frontend part. These are the solutions that came to my mind however I would love to learn the right approach for this. Thank you.
%20 is how a white space is encoded in URL encoding.
There is no single "right way" no handle mapping URLs to objects, but most apps will store a "slug" in the database which is a URL-safe version of the name (or just use a numeric id). You would use the slug to lookup the matching entity. Typically it is all lowercase with spaces replaced by - and other punctuation marks removed. There are plenty of packages and helper functions that can convert special characters, like letters with accent marks, to their plain versions. For example, you can combine deburr and kebabCase from Lodash.
const slugify = (title) => {
return _.kebabCase(_.deburr(title));
}
console.log(slugify("New Shop")); // logs "new-shop"
<script src="https://cdn.jsdelivr.net/npm/lodash#4.17.21/lodash.min.js"></script>

React routes param auto decode string

Hi does react router params automatically decodes string?
For example i have this route
<Route path="/callback/:url"/>
and when I call it with C5jb20%3D
it will print C5jb20= when I console.log() that parameters
Is this an expected behavior? Can I change this behavior so that I still get the encoded string?
Thanks!
C5jb20%3D is a URL encoded string, which is a way to encode special characters in a URL. For example, if you have a URL parameter like ?redirect=/some/path, a server could interpret the forward slashes as routing paths, and mess up the expected routing. That's why you see things like ?redirect=%2Fsome%2Fpath, and your example, in URLs.
window.location.path will have the original, unencoded URL.
You could also get it back with encodeURIComponent:
encodeURIComponent('C5jb20=') // "C5jb20%3D"
You probably don't want to, though, depending on your use case.

Angular ui-router - Curly brackets etc in url

I have been searching for a way to have curly brackets{} and slashes / in the URL. But the URL looks like this:
URL appearance now:
http://localhost/#/?ph=tes:testes%2Ftest%7Blb0%7D
URL wanted appearance:
http://localhost/#/?ph=tes:tests/test{lb0}
How do I get an URL without the %2f etc?
Thanks in advance!
All valid characters that can be used in a URI (a URL is a type of URI) are defined in RFC 3986.
All other characters can be used in a URL provided that they are "URL Encoded" first. This involves changing the invalid character for specific "codes" (usually in the form of the percent symbol (%) followed by a hexadecimal number).
This link, HTML URL Encoding Reference, contains a list of the encodings for invalid characters.
Happy Helping!
These (%2F, %7B) are escape sequences. They represent the special characters that are in your URL, as a URL cannot contain these character directly.
Where do you want exactly to process this URL?
You can use Javascript's unescape(url) to get the escaped URL string back to the original one if you're going to process it in Javascript itself.

AngularJS cyrillic characters and get params

When i try to send cyrillic characters as get params
They are transformed into that
What am I doing wrong?
That's normal, use decodeURIComponent() to decode the url paramaters
http://www.w3schools.com/jsref/jsref_decodeuricomponent.asp

Resources