Skip to content

Commit

Permalink
feat: switch buffer to native Uint8Array (#2288)
Browse files Browse the repository at this point in the history
During this effort querystring-browser library was replaced
by native UrlSearchParams.

Refs #2243
  • Loading branch information
char0n authored Oct 14, 2021
1 parent 3af9b24 commit e96702f
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 34 deletions.
26 changes: 0 additions & 26 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 0 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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"
}
Expand Down
5 changes: 2 additions & 3 deletions src/execute/oas3/style-serializer.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
const { Buffer } = require('buffer');

const isRfc3986Reserved = (char) => ":/?#[]@!$&'()*+,;=".indexOf(char) > -1;
const isRrc3986Unreserved = (char) => /^[a-z0-9\-._~]+$/i.test(char);

Expand Down Expand Up @@ -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('');
Expand Down
8 changes: 5 additions & 3 deletions src/specmap/lib/refs.js
Original file line number Diff line number Diff line change
@@ -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 '.';
Expand Down Expand Up @@ -432,15 +431,18 @@ 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('');
}

/**
* Escapes a JSON pointer.
* @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) {
Expand Down

0 comments on commit e96702f

Please sign in to comment.