Home > Mobile >  Strange characters in an encoded url
Strange characters in an encoded url

Time:10-22

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 d", t.forEach((function(e, n) {
                        t.delete("b"), r  = n   e
                    })), o && !e.toJSON || !t.sort || "http://a/c d?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 || "#б" !== new URL("http://a#б").hash || "a1c3" !== r || "x" !== new URL("http://x", void 0).host
                }))
            },

CodePudding user response:

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.

  • Related