Skip to content

Full Toolkit for Next-Level Domain Analysis

Normalize search input and support unicode domains ✔

Felix Wotschofsky265f618e5194
diff --git a/package.json b/package.json
index 86b5d45..41ae913 100644
--- a/package.json
+++ b/package.json
@@ -12,11 +12,15 @@
"@chakra-ui/react": "^1.6.4",
"@emotion/react": "^11",
"@emotion/styled": "^11",
+ "@types/punycode": "^2.1.0",
+ "@types/validator": "^13.6.3",
"axios": "^0.21.1",
"framer-motion": "^4",
"next": "11.0.0",
+ "punycode": "^2.1.1",
"react": "17.0.2",
- "react-dom": "17.0.2"
+ "react-dom": "17.0.2",
+ "validator": "^13.6.0"
},
"devDependencies": {
"@types/react": "17.0.11",
diff --git a/pages/index.tsx b/pages/index.tsx
index f8e3b09..e3a9c6e 100644
--- a/pages/index.tsx
+++ b/pages/index.tsx
@@ -12,6 +12,8 @@ import {
Flex,
} from '@chakra-ui/react';
import { useRouter } from 'next/router';
+import punycode from 'punycode';
+import validator from 'validator';
enum FormStates {
Initial,
@@ -19,10 +21,6 @@ enum FormStates {
Success,
}
-const domainRegex = new RegExp(
- /^((?:(?:(?:\w[\.\-\+]?)*)\w)+)((?:(?:(?:\w[\.\-\+]?){0,62})\w)+)\.(\w{2,6})$/
-);
-
// Based on simple newsletter template from https://chakra-templates.dev
const Home = () => {
@@ -68,13 +66,17 @@ const Home = () => {
setError(false);
setState(FormStates.Submitting);
- if (!domain.match(domainRegex)) {
+ const normalizedDomain = punycode.toASCII(
+ domain.trim().toLowerCase()
+ );
+
+ if (!validator.isFQDN(normalizedDomain)) {
setError(true);
setState(FormStates.Initial);
return;
}
- router.push(`/lookup/${domain}`);
+ router.push(`/lookup/${normalizedDomain}`);
}}
>
<FormControl>
diff --git a/yarn.lock b/yarn.lock
index 62fa892..67e818c 100644
--- a/yarn.lock
+++ b/yarn.lock
@@ -890,6 +890,11 @@
resolved "https://registry.yarnpkg.com/@types/prop-types/-/prop-types-15.7.3.tgz#2ab0d5da2e5815f94b0b9d4b95d1e5f243ab2ca7"
integrity sha512-KfRL3PuHmqQLOG+2tGpRO26Ctg+Cq1E01D2DMriKEATHgWLfeNDmq9e29Q9WIky0dQ3NPkd1mzYH8Lm936Z9qw==
+"@types/punycode@^2.1.0":
+ version "2.1.0"
+ resolved "https://registry.yarnpkg.com/@types/punycode/-/punycode-2.1.0.tgz#89e4f3d09b3f92e87a80505af19be7e0c31d4e83"
+ integrity sha512-PG5aLpW6PJOeV2fHRslP4IOMWn+G+Uq8CfnyJ+PDS8ndCbU+soO+fB3NKCKo0p/Jh2Y4aPaiQZsrOXFdzpcA6g==
+
version "17.0.11"
resolved "https://registry.yarnpkg.com/@types/react/-/react-17.0.11.tgz#67fcd0ddbf5a0b083a0f94e926c7d63f3b836451"
@@ -909,6 +914,11 @@
resolved "https://registry.yarnpkg.com/@types/tinycolor2/-/tinycolor2-1.4.2.tgz#721ca5c5d1a2988b4a886e35c2ffc5735b6afbdf"
integrity sha512-PeHg/AtdW6aaIO2a+98Xj7rWY4KC1E6yOy7AFknJQ7VXUGNrMlyxDFxJo7HqLtjQms/ZhhQX52mLVW/EX3JGOw==
+"@types/validator@^13.6.3":
+ version "13.6.3"
+ resolved "https://registry.yarnpkg.com/@types/validator/-/validator-13.6.3.tgz#31ca2e997bf13a0fffca30a25747d5b9f7dbb7de"
+ integrity sha512-fWG42pMJOL4jKsDDZZREnXLjc3UE0R8LOJfARWYg6U966rxDT7TYejYzLnUF5cvSObGg34nd0+H2wHHU5Omdfw==
+
"@types/warning@^3.0.0":
version "3.0.0"
resolved "https://registry.yarnpkg.com/@types/warning/-/warning-3.0.0.tgz#0d2501268ad8f9962b740d387c4654f5f8e23e52"
@@ -3247,7 +3257,7 @@ punycode@^1.2.4:
resolved "https://registry.yarnpkg.com/punycode/-/punycode-1.4.1.tgz#c0d5a63b2718800ad8e1eb0fa5269c84dd41845e"
integrity sha1-wNWmOycYgArY4esPpSachN1BhF4=
-punycode@^2.1.0:
+punycode@^2.1.0, 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==
@@ -4083,6 +4093,11 @@ validate-npm-package-license@^3.0.1:
spdx-correct "^3.0.0"
spdx-expression-parse "^3.0.0"
+validator@^13.6.0:
+ version "13.6.0"
+ resolved "https://registry.yarnpkg.com/validator/-/validator-13.6.0.tgz#1e71899c14cdc7b2068463cb24c1cc16f6ec7059"
+ integrity sha512-gVgKbdbHgtxpRyR8K0O6oFZPhhB5tT1jeEHZR0Znr9Svg03U0+r9DXWMrnRAB+HtCStDQKlaIZm42tVsVjqtjg==
+
[email protected], vm-browserify@^1.0.1:
version "1.1.2"
resolved "https://registry.yarnpkg.com/vm-browserify/-/vm-browserify-1.1.2.tgz#78641c488b8e6ca91a75f511e7a3b32a86e5dda0"