diff options
Diffstat (limited to 'ext/node/polyfills')
-rw-r--r-- | ext/node/polyfills/dns.ts | 12 | ||||
-rw-r--r-- | ext/node/polyfills/internal/idna.ts | 19 | ||||
-rw-r--r-- | ext/node/polyfills/punycode.ts | 24 | ||||
-rw-r--r-- | ext/node/polyfills/url.ts | 13 |
4 files changed, 54 insertions, 14 deletions
diff --git a/ext/node/polyfills/dns.ts b/ext/node/polyfills/dns.ts index 3b3565cb3..78b934e60 100644 --- a/ext/node/polyfills/dns.ts +++ b/ext/node/polyfills/dns.ts @@ -92,7 +92,7 @@ import { GetAddrInfoReqWrap, QueryReqWrap, } from "ext:deno_node/internal_binding/cares_wrap.ts"; -import { toASCII } from "node:punycode"; +import { domainToASCII } from "ext:deno_node/internal/idna.ts"; import { notImplemented } from "ext:deno_node/_utils.ts"; function onlookup( @@ -264,7 +264,13 @@ export function lookup( req.hostname = hostname; req.oncomplete = all ? onlookupall : onlookup; - const err = getaddrinfo(req, toASCII(hostname), family, hints, verbatim); + const err = getaddrinfo( + req, + domainToASCII(hostname), + family, + hints, + verbatim, + ); if (err) { nextTick( @@ -332,7 +338,7 @@ function resolver(bindingName: keyof ChannelWrapQuery) { req.ttl = !!(options && (options as ResolveOptions).ttl); - const err = this._handle[bindingName](req, toASCII(name)); + const err = this._handle[bindingName](req, domainToASCII(name)); if (err) { throw dnsException(err, bindingName, name); diff --git a/ext/node/polyfills/internal/idna.ts b/ext/node/polyfills/internal/idna.ts index 6484fe951..93ed065cc 100644 --- a/ext/node/polyfills/internal/idna.ts +++ b/ext/node/polyfills/internal/idna.ts @@ -51,6 +51,11 @@ "use strict"; +import { + op_node_idna_domain_to_ascii, + op_node_idna_domain_to_unicode, +} from "ext:core/ops"; + /** * Creates an array containing the numeric code points of each Unicode * character in the string. While JavaScript uses UCS-2 internally, @@ -105,3 +110,17 @@ export const ucs2 = { decode: ucs2decode, encode: ucs2encode, }; + +/** + * Converts a domain to ASCII as per the IDNA spec + */ +export function domainToASCII(domain: string) { + return op_node_idna_domain_to_ascii(domain); +} + +/** + * Converts a domain to Unicode as per the IDNA spec + */ +export function domainToUnicode(domain: string) { + return op_node_idna_domain_to_unicode(domain); +} diff --git a/ext/node/polyfills/punycode.ts b/ext/node/polyfills/punycode.ts index 6f137d31f..e89be15a2 100644 --- a/ext/node/polyfills/punycode.ts +++ b/ext/node/polyfills/punycode.ts @@ -1,28 +1,40 @@ // Copyright 2018-2024 the Deno authors. All rights reserved. MIT license. import { - op_node_idna_domain_to_ascii, - op_node_idna_domain_to_unicode, op_node_idna_punycode_decode, op_node_idna_punycode_encode, + op_node_idna_punycode_to_ascii, + op_node_idna_punycode_to_unicode, } from "ext:core/ops"; +import { deprecate } from "node:util"; + import { ucs2 } from "ext:deno_node/internal/idna.ts"; +// deno-lint-ignore no-explicit-any +function punyDeprecated(fn: any) { + return deprecate( + fn, + "The `punycode` module is deprecated. Please use a userland " + + "alternative instead.", + "DEP0040", + ); +} + function toASCII(domain) { - return op_node_idna_domain_to_ascii(domain); + return punyDeprecated(op_node_idna_punycode_to_ascii)(domain); } function toUnicode(domain) { - return op_node_idna_domain_to_unicode(domain); + return punyDeprecated(op_node_idna_punycode_to_unicode)(domain); } function decode(domain) { - return op_node_idna_punycode_decode(domain); + return punyDeprecated(op_node_idna_punycode_decode)(domain); } function encode(domain) { - return op_node_idna_punycode_encode(domain); + return punyDeprecated(op_node_idna_punycode_encode)(domain); } export { decode, encode, toASCII, toUnicode, ucs2 }; diff --git a/ext/node/polyfills/url.ts b/ext/node/polyfills/url.ts index 14195d146..6633334ba 100644 --- a/ext/node/polyfills/url.ts +++ b/ext/node/polyfills/url.ts @@ -70,7 +70,10 @@ import { CHAR_ZERO_WIDTH_NOBREAK_SPACE, } from "ext:deno_node/path/_constants.ts"; import * as path from "node:path"; -import { toASCII, toUnicode } from "node:punycode"; +import { + domainToASCII as idnaToASCII, + domainToUnicode as idnaToUnicode, +} from "ext:deno_node/internal/idna.ts"; import { isWindows, osType } from "ext:deno_node/_util/os.ts"; import { encodeStr, hexTable } from "ext:deno_node/internal/querystring.ts"; import querystring from "node:querystring"; @@ -813,7 +816,7 @@ export class Url { // Use lenient mode (`true`) to try to support even non-compliant // URLs. - this.hostname = toASCII(this.hostname); + this.hostname = idnaToASCII(this.hostname); // Prevent two potential routes of hostname spoofing. // 1. If this.hostname is empty, it must have become empty due to toASCII @@ -1251,7 +1254,7 @@ export function resolveObject(source: string | Url, relative: string) { * @see https://www.rfc-editor.org/rfc/rfc3490#section-4 */ export function domainToASCII(domain: string) { - return toASCII(domain); + return idnaToASCII(domain); } /** @@ -1261,7 +1264,7 @@ export function domainToASCII(domain: string) { * @see https://www.rfc-editor.org/rfc/rfc3490#section-4 */ export function domainToUnicode(domain: string) { - return toUnicode(domain); + return idnaToUnicode(domain); } /** @@ -1396,7 +1399,7 @@ export function pathToFileURL(filepath: string): URL { ); } - outURL.hostname = domainToASCII(hostname); + outURL.hostname = idnaToASCII(hostname); outURL.pathname = encodePathChars(paths.slice(3).join("/")); } else { let resolved = path.resolve(filepath); |