Handle punycode on /tld/

parent f7c74421
......@@ -64,6 +64,11 @@ twig.extendFunction("getReverse", (ipAddr: string): string => {
return "";
})
import punycode from "punycode";
twig.extendFunction("punycodeToASCII", (input: string): string => {
return punycode.toASCII(input);
});
/**
* Is server in production mode?
*/
......@@ -233,7 +238,7 @@ twig.extendFunction("getBadge", (badgeName: string, asn?: number, pdb?, pdbDataT
});
function getCountryName(countryCode) {
function getCountryName(countryCode, returnSame?) {
countryCode = countryCode.toUpperCase();
if(countryCode === "EU") {
return "European Union";
......@@ -247,6 +252,10 @@ function getCountryName(countryCode) {
countryName = country.name;
} catch {}
if(returnSame === "no" && countryName == countryCode) {
return;
}
return countryName;
}
......@@ -254,9 +263,19 @@ function getCountryName(countryCode) {
* UI feature:
* ISO 3166-1 alpha-2 to English
* aka "Get country code"
*
* If "returnSame" is not "no" and country is not found, the query is returned
*/
twig.extendFunction("countryCode", (countryCode) => {
return getCountryName(countryCode);
twig.extendFunction("countryCode", (countryCode, returnSame?, addParenthesis?) => {
const result = getCountryName(countryCode, returnSame);
if(addParenthesis === "yes" && result != undefined) {
return `(${result})`;
} else if (result != undefined) {
return;
}
return result;
})
/**
......
import { NextFunction, Request, Response, Router } from "express";
import axios from "axios";
import isDomainName from "is-domain-name";
import punycode from "punycode";
const { Resolver } = require('dns').promises;
const resolver = new Resolver();
......@@ -92,9 +93,10 @@ router.get("/:tld", (req: Request, res: Response, next: NextFunction) => {
.then(nameserverAddresses => {
res.render("tld/show.twig", {
"canonical_url": `/tld/${tld}`,
"title": `Information about .${tld}`,
"title": `Information about .${punycode.toUnicode(tld)}`,
"tld": tld,
"tldUnicode": punycode.toUnicode(tld),
"nameservers": nameservers,
......
......@@ -12,11 +12,11 @@
{% else %}
<li>
<a href="/tld/{{ domain }}">
<a href="/tld/{{ punycodeToASCII(domain) }}">
{{ domain }}
</a>
{% if domain|length == 2 %}
({{ countryCode(domain) }})
{{ countryCode(domain, "no", "yes") }}
{% endif %}
</li>
......
......@@ -3,6 +3,10 @@
{% block body %}
<h1>{{ title }}</h1>
{% if tldUnicode != tld %}
<p>Punycode: <code>.{{ tld }}</code></p>
{% endif %}
<h2>Nameservers</h2>
<table class="table w-auto">
<thead>
......
......@@ -2874,6 +2874,11 @@ pstree.remy@^1.1.6:
resolved "https://registry.yarnpkg.com/pstree.remy/-/pstree.remy-1.1.7.tgz#c76963a28047ed61542dc361aa26ee55a7fa15f3"
integrity sha512-xsMgrUwRpuGskEzBFkH8NmTimbZ5PcPup0LA8JJkHIm2IMUbQcpo3yeLNWVrufEYjh8YwtSVh0xz6UeWc5Oh5A==
punycode@^2.1.1:
version "2.1.1"
resolved "https://registry.yarnpkg.com/punycode/-/punycode-2.1.1.tgz#b58b010ac40c22c5657616c8d2c2c02c7bf479ec"
integrity sha512-XRsRjdf+j5ml+y/6GKHPZbrF/8p2Yga0JPtdqTIY2Xe5ohJPD9saDJJLPvp9+NSBprVvevdXZybnj2cv8OEd0A==
qs@6.7.0:
version "6.7.0"
resolved "https://registry.yarnpkg.com/qs/-/qs-6.7.0.tgz#41dc1a015e3d581f1621776be31afb2876a9b1bc"
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment