From af39df6d034213d7ae9c500c3af082ecb2eeeac2 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 Reviewed-By: Zijian Liu Reviewed-By: James M Snell --- lib/.eslintrc.yaml | 4 ++++ lib/internal/freeze_intrinsics.js | 4 ++++ lib/internal/per_context/primordials.js | 10 ++++++++++ lib/internal/url.js | 1 + lib/querystring.js | 1 + lib/url.js | 1 + 6 files changed, 21 insertions(+) diff --git a/lib/.eslintrc.yaml b/lib/.eslintrc.yaml index deea6bf4fb05ae..05142865e12802 100644 --- a/lib/.eslintrc.yaml +++ b/lib/.eslintrc.yaml @@ -38,6 +38,10 @@ rules: - name: Boolean - name: DataView - name: Date + - name: decodeURI + - name: decodeURIComponent + - name: encodeURI + - name: encodeURIComponent - name: Error ignore: - prepareStackTrace diff --git a/lib/internal/freeze_intrinsics.js b/lib/internal/freeze_intrinsics.js index 50ae655206479a..a1cdd64d06cbaa 100644 --- a/lib/internal/freeze_intrinsics.js +++ b/lib/internal/freeze_intrinsics.js @@ -107,6 +107,10 @@ const { WeakMapPrototype, WeakSet, WeakSetPrototype, + decodeURI, + decodeURIComponent, + encodeURI, + encodeURIComponent, } = primordials; module.exports = function() { diff --git a/lib/internal/per_context/primordials.js b/lib/internal/per_context/primordials.js index 756c774d8b6379..874fd224da274b 100644 --- a/lib/internal/per_context/primordials.js +++ b/lib/internal/per_context/primordials.js @@ -173,6 +173,16 @@ primordials.SafeWeakSet = makeSafe( } ); +// 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 24d85353686534..fc474cf154f2ec 100644 --- a/lib/internal/url.js +++ b/lib/internal/url.js @@ -30,6 +30,7 @@ const { Symbol, SymbolIterator, SymbolToStringTag, + decodeURIComponent, } = primordials; const { inspect } = require('internal/util/inspect'); diff --git a/lib/querystring.js b/lib/querystring.js index 848a6c3afbe8ad..84e93817f96e89 100644 --- a/lib/querystring.js +++ b/lib/querystring.js @@ -34,6 +34,7 @@ const { String, StringPrototypeCharCodeAt, StringPrototypeSlice, + decodeURIComponent, } = primordials; const { Buffer } = require('buffer'); diff --git a/lib/url.js b/lib/url.js index 49f99a8b5fa621..2976e7d2d8c5ac 100644 --- a/lib/url.js +++ b/lib/url.js @@ -27,6 +27,7 @@ const { ObjectKeys, SafeSet, StringPrototypeCharCodeAt, + decodeURIComponent, } = primordials; const { toASCII } = require('internal/idna');