From e96702ff4a6d30ccecb2f6f07774110baaa3bb36 Mon Sep 17 00:00:00 2001 From: Vladimir Gorej Date: Thu, 14 Oct 2021 10:45:29 +0300 Subject: [PATCH] feat: switch buffer to native Uint8Array (#2288) During this effort querystring-browser library was replaced by native UrlSearchParams. Refs #2243 --- package-lock.json | 26 -------------------------- package.json | 2 -- src/execute/oas3/style-serializer.js | 5 ++--- src/specmap/lib/refs.js | 8 +++++--- 4 files changed, 7 insertions(+), 34 deletions(-) diff --git a/package-lock.json b/package-lock.json index c9e853c47..56f3e4e39 100644 --- a/package-lock.json +++ b/package-lock.json @@ -5583,11 +5583,6 @@ "integrity": "sha1-ibTRmasr7kneFk6gK4nORi1xt2c=", "dev": true }, - "base64-js": { - "version": "1.3.1", - "resolved": "https://registry.npmjs.org/base64-js/-/base64-js-1.3.1.tgz", - "integrity": "sha512-mLQ4i2QO1ytvGWFWmcngKO//JXAQueZvwEKtjgQFM4jIK0kU+ytMfplL8j+n5mspOfjHwoAg+9yhb7BwAHm36g==" - }, "big.js": { "version": "5.2.2", "resolved": "https://registry.npmjs.org/big.js/-/big.js-5.2.2.tgz", @@ -5667,22 +5662,6 @@ "resolved": "https://registry.npmjs.org/btoa/-/btoa-1.2.1.tgz", "integrity": "sha512-SB4/MIGlsiVkMcHmT+pSmIPoNDoHg+7cMzmt3Uxt628MTz2487DKSqK/fuhFBrkuqrYv5UCEnACpF4dTFNKc/g==" }, - "buffer": { - "version": "6.0.3", - "resolved": "https://registry.npmjs.org/buffer/-/buffer-6.0.3.tgz", - "integrity": "sha512-FTiCpNxtwiZZHEZbcbTIcZjERVICn9yq/pDFkTl95/AxzD1naBctN7YO68riM/gLSDY7sdrMby8hofADYuuqOA==", - "requires": { - "base64-js": "^1.3.1", - "ieee754": "^1.2.1" - }, - "dependencies": { - "ieee754": { - "version": "1.2.1", - "resolved": "https://registry.npmjs.org/ieee754/-/ieee754-1.2.1.tgz", - "integrity": "sha512-dcyqhDvX1C46lXZcVqCpK+FtMRQVdIMN6/Df5js2zouUsqG7I6sFxitIC+7KYK29KdXOLHdu9zL4sFnoVQnqaA==" - } - } - }, "buffer-from": { "version": "1.1.1", "resolved": "https://registry.npmjs.org/buffer-from/-/buffer-from-1.1.1.tgz", @@ -11341,11 +11320,6 @@ "resolved": "https://registry.npmjs.org/querystring/-/querystring-0.2.0.tgz", "integrity": "sha1-sgmEkgO7Jd+CDadW50cAWHhSFiA=" }, - "querystring-browser": { - "version": "1.0.4", - "resolved": "https://registry.npmjs.org/querystring-browser/-/querystring-browser-1.0.4.tgz", - "integrity": "sha1-8uNYgYQKgZvHsb9Zf68JeeZiLcY=" - }, "quick-lru": { "version": "4.0.1", "resolved": "https://registry.npmjs.org/quick-lru/-/quick-lru-4.0.1.tgz", diff --git a/package.json b/package.json index c6283ed8d..6b7f430a2 100644 --- a/package.json +++ b/package.json @@ -109,7 +109,6 @@ "dependencies": { "@babel/runtime-corejs3": "^7.11.2", "btoa": "^1.2.1", - "buffer": "^6.0.3", "cookie": "~0.4.1", "cross-fetch": "^3.1.4", "deep-extend": "~0.6.0", @@ -119,7 +118,6 @@ "js-yaml": "^4.1.0", "lodash": "^4.17.21", "qs": "^6.9.4", - "querystring-browser": "^1.0.4", "traverse": "~0.6.6", "url": "~0.11.0" } diff --git a/src/execute/oas3/style-serializer.js b/src/execute/oas3/style-serializer.js index 76862f63d..a8ab0a386 100644 --- a/src/execute/oas3/style-serializer.js +++ b/src/execute/oas3/style-serializer.js @@ -1,5 +1,3 @@ -const { Buffer } = require('buffer'); - const isRfc3986Reserved = (char) => ":/?#[]@!$&'()*+,;=".indexOf(char) > -1; const isRrc3986Unreserved = (char) => /^[a-z0-9\-._~]+$/i.test(char); @@ -33,7 +31,8 @@ export function encodeDisallowedCharacters(str, { escape } = {}, parse) { return char; } - const encoded = (Buffer.from(char).toJSON().data || []) + const encoder = new TextEncoder(); + const encoded = Array.from(encoder.encode(char)) .map((byte) => `0${byte.toString(16).toUpperCase()}`.slice(-2)) .map((encodedByte) => `%${encodedByte}`) .join(''); diff --git a/src/specmap/lib/refs.js b/src/specmap/lib/refs.js index 69862aa51..f11b9c7e6 100644 --- a/src/specmap/lib/refs.js +++ b/src/specmap/lib/refs.js @@ -1,6 +1,5 @@ import 'cross-fetch/polyfill'; /* global fetch */ import jsYaml from 'js-yaml'; -import qs from 'querystring-browser'; import url from 'url'; import lib from '.'; @@ -432,7 +431,9 @@ function unescapeJsonPointerToken(token) { if (typeof token !== 'string') { return token; } - return qs.unescape(token.replace(/~1/g, '/').replace(/~0/g, '~')); + + const params = new URLSearchParams(`=${token.replace(/~1/g, '/').replace(/~0/g, '~')}`); + return params.get(''); } /** @@ -440,7 +441,8 @@ function unescapeJsonPointerToken(token) { * @api public */ function escapeJsonPointerToken(token) { - return qs.escape(token.replace(/~/g, '~0').replace(/\//g, '~1')); + const params = new URLSearchParams([['', token.replace(/~/g, '~0').replace(/\//g, '~1')]]); + return params.toString().slice(1); } function arrayToJsonPointer(arr) {