From 2da24ac302167ec346965d92dfe5dea3ee5c9424 Mon Sep 17 00:00:00 2001 From: Antoine du Hamel Date: Tue, 16 Feb 2021 14:31:29 +0100 Subject: [PATCH] lib: add URI handling functions to primordials PR-URL: https://github.com/nodejs/node/pull/37394 Backport-PR-URL: https://github.com/nodejs/node/pull/37859 Reviewed-By: Zijian Liu Reviewed-By: James M Snell --- lib/internal/per_context/primordials.js | 10 ++++++++++ lib/internal/url.js | 1 + lib/querystring.js | 1 + lib/url.js | 1 + 4 files changed, 13 insertions(+) diff --git a/lib/internal/per_context/primordials.js b/lib/internal/per_context/primordials.js index 09bea0fc7fc523..6a960f36feda45 100644 --- a/lib/internal/per_context/primordials.js +++ b/lib/internal/per_context/primordials.js @@ -106,6 +106,16 @@ primordials.SafePromise = makeSafe( class SafePromise extends Promise {} ); +// Create copies of URI handling functions +[ + decodeURI, + decodeURIComponent, + encodeURI, + encodeURIComponent, +].forEach((fn) => { + primordials[fn.name] = fn; +}); + // Create copies of the namespace objects [ 'JSON', diff --git a/lib/internal/url.js b/lib/internal/url.js index 16f5043df9c641..2c0b1f518a7091 100644 --- a/lib/internal/url.js +++ b/lib/internal/url.js @@ -14,6 +14,7 @@ const { Symbol, SymbolIterator, SymbolToStringTag, + decodeURIComponent, } = primordials; const { inspect } = require('internal/util/inspect'); diff --git a/lib/querystring.js b/lib/querystring.js index 4d196633dcf2c7..7bc6684f400174 100644 --- a/lib/querystring.js +++ b/lib/querystring.js @@ -29,6 +29,7 @@ const { MathAbs, ObjectCreate, ObjectKeys, + decodeURIComponent, } = primordials; const { Buffer } = require('buffer'); diff --git a/lib/url.js b/lib/url.js index 735390dfd2e59b..f7dbebea5ac125 100644 --- a/lib/url.js +++ b/lib/url.js @@ -25,6 +25,7 @@ const { ObjectCreate, ObjectKeys, SafeSet, + decodeURIComponent, } = primordials; const { toASCII } = require('internal/idna');