From b7a593d7ea9df025e580c1d3d6b5bce6e046f4e7 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 358a3ffb1909ea..1840f859e54fcc 100644 --- a/lib/internal/per_context/primordials.js +++ b/lib/internal/per_context/primordials.js @@ -137,6 +137,16 @@ function copyPrototype(src, dest, prefix) { } } +// 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 4fd7702367e8a6..6660cea55f1c4e 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 658c9c052fe9b6..c79831b359d8f6 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 a13988031241d0..0fb81e277c512b 100644 --- a/lib/url.js +++ b/lib/url.js @@ -27,6 +27,7 @@ const { ObjectKeys, SafeSet, StringPrototypeCharCodeAt, + decodeURIComponent, } = primordials; const { toASCII } = require('internal/idna');