Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Strange characters in an encoded url

I recently came across what seems to be an encoded url scheme, which has some odd characters, and I would like to know how it was encoded and perhaps the purpose. I’ve included the whole function, but pay attention to new URL("http://теÑÑ‚").host in particular.

590: (e, t, r) => {
                var n = r(7293),
                    i = r(5112),
                    o = r(1913),
                    a = i("iterator");
                e.exports = !n((function() {
                    var e = new URL("b?a=1&b=2&c=3", "http://a"),
                        t = e.searchParams,
                        r = "";
                    return e.pathname = "c%20d", t.forEach((function(e, n) {
                        t.delete("b"), r += n + e
                    })), o && !e.toJSON || !t.sort || "http://a/c%20d?a=1&c=3" !== e.href || "3" !== t.get("c") || "a=1" !== String(new URLSearchParams("?a=1")) || !t[a] || "a" !== new URL("https://a@b").username || "b" !== new URLSearchParams(new URLSearchParams("a=b")).get("a") || "xn--e1aybc" !== new URL("http://теÑÑ‚").host || "#%D0%B1" !== new URL("http://a#б").hash || "a1c3" !== r || "x" !== new URL("http://x", void 0).host
                }))
            },

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

In

"xn--e1aybc" !== new URL("http://теÑÑ‚").host

теÑÑ‚ is just an arbitrary string containing some Unicode characters. Hostnames in URLs are supposed to be written just using ASCII, so an encoding called Punycode was designed; the prefix xn-- indicates that the rest of the hostname is Punycode.

xn--e1aybc is the Punycode encoding for that hostname, and this is testing whether the new URL() constructor performs the proper encoding.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading