Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

idna-uts46-hx

Package Overview
Dependencies
Maintainers
1
Versions
47
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

idna-uts46-hx - npm Package Compare versions

Comparing version 2.0.2 to 2.1.0

2

package.json
{
"name": "idna-uts46-hx",
"version": "2.0.2",
"version": "2.1.0",
"description": "A UTS #46 processing algorithm for IDNA2008 strings",

@@ -5,0 +5,0 @@ "main": "uts46.js",

@@ -35,3 +35,3 @@ # IDNA-UTS #46 in JavaScript

### `uts46.toAscii(domain, options={transitional: false, useStd3ASCII:false })`
### `uts46.toAscii(domain, options={transitional: false, useStd3ASCII: false, verifyDnsLength: false })`

@@ -43,4 +43,7 @@ Converts a domain name to the correct ASCII label. The second parameter is an

false. The `useStd3ASCII` option controls whether or not characters that are
illegal in domain names per the DNS specification should be omitted. Both of the
latter parameters are optional and should be omitted for most users.
illegal in domain names per the DNS specification should be omitted. The
`verifyDnsLength` option controls whether or not the resulting DNS label should
be checked for length validity (i.e., no empty components and not too long). The
options parameter and its associated fields are all optional and should be
omitted for most users.

@@ -86,8 +89,6 @@ ```js

This code does not implement the verifyDNSLength parameter of the UTS #46
algorithm (largely because the WHATWG URL specification does not use said
parameter). It also does not try to implement the Bidi and contextual rules for
validation: these do not affect any mapping of the domain names; instead, they
restrict the set of valid domain names. Since registrars shouldn't be accepting
these names in the first place, a domain that violates these rules will simply
fail to resolve.
It also does not try to implement the Bidi and contextual rules for validation:
these do not affect any mapping of the domain names; instead, they restrict the
set of valid domain names. Since registrars shouldn't be accepting these names
in the first place, a domain that violates these rules will simply fail to
resolve.

@@ -31,3 +31,42 @@ "use strict";

});
// Check verify DNS length
assert.equal(uts46.toAscii("", {
verifyDnsLength: false
}), "");
assert.throws(function() {
uts46.toAscii("", {
verifyDnsLength: true
});
});
});
test('Verify DNS length parameter', function() {
assert.throws(function() {
uts46.toAscii("this..is.almost.right", {
verifyDnsLength: true
});
});
assert.throws(function() {
uts46.toAscii("a.".repeat(252 / 2) + "aa", {
verifyDnsLength: true
});
});
assert.doesNotThrow(function() {
// Exactly 253 characters.
uts46.toAscii("a.".repeat(252 / 2) + "a", {
verifyDnsLength: true
});
});
assert.throws(function() {
uts46.toAscii("a".repeat(64), {
verifyDnsLength: true
});
});
assert.doesNotThrow(function() {
uts46.toAscii("a".repeat(63), {
verifyDnsLength: true
});
});
// Default is to not verify it.
assert.equal(uts46.toAscii(""), "");
});
test('Defaults to transitional', function() {

@@ -34,0 +73,0 @@ assert.equal("fass.de", uts46.toAscii("faß.de"));

@@ -101,4 +101,16 @@ (function(root, factory) {

var useStd3ASCII = 'useStd3ASCII' in options ? options.useStd3ASCII : false;
var verifyDnsLength = 'verifyDnsLength' in options ? options.verifyDnsLength : false;
var labels = process(domain, transitional, useStd3ASCII).split('.');
return labels.map(punycode.toASCII).join('.');
var asciiLabels = labels.map(punycode.toASCII);
var asciiString = asciiLabels.join('.');
if (verifyDnsLength) {
if (asciiString.length < 1 || asciiString.length > 253) {
throw new Error("DNS name has wrong length: " + asciiString);
}
for (var label of asciiLabels) {
if (label.length < 1 || label.length > 63)
throw new Error("DNS label has wrong length: " + label);
}
}
return asciiString;
}

@@ -105,0 +117,0 @@

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc