Skip to content

Instantly share code, notes, and snippets.

@hUwUtao
Last active September 4, 2024 17:57
Show Gist options
  • Save hUwUtao/3cbd9dc0ec20fd3c0e891d9a3e1e161b to your computer and use it in GitHub Desktop.
Save hUwUtao/3cbd9dc0ec20fd3c0e891d9a3e1e161b to your computer and use it in GitHub Desktop.
Force UrlEncode URL (might not webserver compliant)
"".split("/")
.map((p, i) =>
i >= 3
? p
.split("")
.map((c) =>
"?#".includes(c)
? c
: `%${c.charCodeAt(0).toString(16).padStart(2, "0")}`,
)
.join("")
: p,
)
.join("/")
.split("/").map((i,a)=>a>=3?i.split("").map(t=>"?#".includes(t)?t:`%${t.charCodeAt(0).toString(16).padStart(2,"0")}`).join(""):i).join("/")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment