diff --git a/css/dns.css b/css/dns.css
index c01450d..cca34f7 100644
--- a/css/dns.css
+++ b/css/dns.css
@@ -909,7 +909,6 @@ nav .container-inner {
font-size: 40px;
line-height: 48px;
color: var(--text-primary);
- margin-bottom: 24px;
word-break: break-all;
text-align: center;
}
@@ -918,6 +917,15 @@ nav .container-inner {
font-size: 32px;
}
+#domainPunyName {
+ font-weight: 600;
+ line-height: 48px;
+ color: var(--text-primary);
+ margin-bottom: 24px;
+ word-break: break-all;
+ text-align: center;
+}
+
.status {
flex-direction: row;
justify-content: center;
diff --git a/index.html b/index.html
index dce7155..25fb0ad 100644
--- a/index.html
+++ b/index.html
@@ -224,6 +224,8 @@
@@ -910,6 +912,7 @@
Get .ton domains
+
diff --git a/src/index.js b/src/index.js
index 1073c17..560b5c3 100644
--- a/src/index.js
+++ b/src/index.js
@@ -100,25 +100,21 @@ $('.badge__dns-mobile').addEventListener('click', () => {
// SET DOMAIN
+const validateDomainChars = (domain) => {
+ return !!domain.match(/^[0-9A-Za-z-]+$/) // '-' or 0-9 or a-z ; abcdefghijklmnopqrstuvwxyz-0123456789
+}
+
const validateDomain = (domain) => {
if (domain.length < 4 || domain.length > 126) {
return store.localeDict.error_length
}
- for (let i = 0; i < domain.length; i++) {
- if (domain.charAt(i) === '.') {
- return store.localeDict.subdomains_not_allowed
- }
- const char = domain.charCodeAt(i)
- const isHyphen = char === 45
- const isValidChar =
- (isHyphen && i > 0 && i < domain.length - 1) ||
- (char >= 48 && char <= 57) ||
- (char >= 97 && char <= 122) // '-' or 0-9 or a-z ; abcdefghijklmnopqrstuvwxyz-0123456789
-
- if (!isValidChar) {
- return store.localeDict.invalid_chars
- }
+ if (domain.includes('.')) {
+ return store.localeDict.subdomains_not_allowed
+ }
+
+ if (!validateDomainChars(domain)) {
+ return store.localeDict.invalid_chars
}
}
@@ -276,7 +272,8 @@ const setDomain = (domain, isTimerMounted) => {
$('.start-input').value = ''
setCareeteHelperValue('')
- setDomainName(domain, $('#domainName'))
+ setDomainName(normalizeDomain(domain), $('#domainName'))
+ $('#domainPunyName').innerText = isPunycode(domain) ? `(${domain}.ton)` : ''
setScreen('main')
clearInterval(updateIntervalId)
@@ -314,6 +311,9 @@ const onInput = (e) => {
if (domain.endsWith('.ton')) {
domain = domain.substring(0, domain.length - 4)
}
+ if (!validateDomainChars(domain)) {
+ domain = idnaUts46.toAscii(domain)
+ }
const error = validateDomain(domain)
if (error) {
setError($('.start-error'), error)
@@ -560,6 +560,7 @@ const renderSearchHistory = (node) => {
try {
const historyMarkup = getHistoryFromStorage().map(
(historyRecord) => {
+ const normalizedDomain = normalizeDomain(historyRecord)
const sanitizedValue = encodeHTML(historyRecord)
return `