From 3e5f7e2e374f1050ff4f3db4b1c35151ef628044 Mon Sep 17 00:00:00 2001 From: jdalton Date: Tue, 10 Sep 2024 16:51:40 -0400 Subject: [PATCH] Add querystringify test --- .taprc | 1 + packages/npm/querystringify/index.js | 35 +++++++++++++++---- test/npm.test.ts | 2 +- test/npm/define-properties/package-lock.json | 17 ++------- test/npm/define-properties/package.json | 4 +-- test/npm/querystringify/index.js | 3 ++ test/npm/querystringify/package-lock.json | 19 ++++++++++ test/npm/querystringify/package.json | 10 ++++++ .../patches/querystringify+2.2.0.patch | 12 +++++++ 9 files changed, 79 insertions(+), 24 deletions(-) create mode 100644 test/npm/querystringify/index.js create mode 100644 test/npm/querystringify/package-lock.json create mode 100644 test/npm/querystringify/package.json create mode 100644 test/npm/querystringify/patches/querystringify+2.2.0.patch diff --git a/.taprc b/.taprc index 5dc1e21a..40ab61eb 100644 --- a/.taprc +++ b/.taprc @@ -9,6 +9,7 @@ disable-coverage: true coverage-report: - none reporter: terse +passes: true plugin: - "!@tapjs/spawn" - "!@tapjs/stdin" diff --git a/packages/npm/querystringify/index.js b/packages/npm/querystringify/index.js index 5244130d..ae60fe5d 100644 --- a/packages/npm/querystringify/index.js +++ b/packages/npm/querystringify/index.js @@ -1,20 +1,41 @@ 'use strict' +function decode(encoded) { + try { + return decodeURIComponent(encoded) + } catch {} + return undefined +} + function parse(query) { - if (typeof query !== 'string' || query.length === 0) { - return {} - } - return Object.fromEntries( + const result = {} + if (typeof query === 'string' && query.length > 0) { new URLSearchParams( query.charCodeAt(0) === 35 /*'#'*/ ? query.slice(1) : query - ).entries() - ) + ).forEach((value, key_) => { + const key = decode(key_) + if (key === undefined || key in result) return + result[key] = decode(value) + }) + } + return result } function stringify(obj, prefix = '') { const params = obj !== null && typeof obj === 'object' - ? new URLSearchParams(obj).toString() + ? new URLSearchParams( + Object.fromEntries( + Object.entries(obj).map(pairs => { + const { 1: value } = pairs + return value === null || + value === undefined || + (!value && isNaN(value)) + ? [pairs[0], ''] + : pairs + }) + ) + ).toString() : '' if (params.length === 0) { return '' diff --git a/test/npm.test.ts b/test/npm.test.ts index b5b095ab..f80c45f3 100644 --- a/test/npm.test.ts +++ b/test/npm.test.ts @@ -31,7 +31,7 @@ const tapeBinPath = fs.realpathSync(path.join(binPath, 'tape')) scripts: { test } } = pkgJson - describe(pkgName, async () => { + describe(pkgName, () => { it('should pass all unit tests', async () => { const args = yargsParser(test)._.map(n => n === 'tape' ? tapeBinPath : stripQuotes(`${n}`) diff --git a/test/npm/define-properties/package-lock.json b/test/npm/define-properties/package-lock.json index a9fc71b1..925da14c 100644 --- a/test/npm/define-properties/package-lock.json +++ b/test/npm/define-properties/package-lock.json @@ -5,7 +5,7 @@ "packages": { "": { "devDependencies": { - "define-properties": "git://github.com/ljharb/define-properties.git#v1.2.1" + "define-properties": "https://github.com/ljharb/define-properties/archive/d7a4db30214eb06d3997dc3e662c11dfe95b25bd.tar.gz" } }, "node_modules/define-data-property": { @@ -13,7 +13,6 @@ "resolved": "https://registry.npmjs.org/define-data-property/-/define-data-property-1.1.4.tgz", "integrity": "sha512-rBMvIzlpA8v6E+SJZoo++HAYqsLrkg7MSfIinMPFhmkorw7X+dOXVJQs+QT69zGkzMyfDnIMN2Wid1+NbL3T+A==", "dev": true, - "license": "MIT", "dependencies": { "es-define-property": "^1.0.0", "es-errors": "^1.3.0", @@ -28,9 +27,9 @@ }, "node_modules/define-properties": { "version": "1.2.1", - "resolved": "git+ssh://git@github.com/ljharb/define-properties.git#d7a4db30214eb06d3997dc3e662c11dfe95b25bd", + "resolved": "https://github.com/ljharb/define-properties/archive/d7a4db30214eb06d3997dc3e662c11dfe95b25bd.tar.gz", + "integrity": "sha512-hoykdDScBwSkL2DKPAbJ2u4Mz/mLOoIAXMw9Ru+QDLnlgb77eaZU5TgTWs3ZLpu/DPrSJabibDaa757s6Zmf8Q==", "dev": true, - "license": "MIT", "dependencies": { "define-data-property": "^1.0.1", "has-property-descriptors": "^1.0.0", @@ -48,7 +47,6 @@ "resolved": "https://registry.npmjs.org/es-define-property/-/es-define-property-1.0.0.tgz", "integrity": "sha512-jxayLKShrEqqzJ0eumQbVhTYQM27CfT1T35+gCgDFoL82JLsXqTJ76zv6A0YLOgEnLUMvLzsDsGIrl8NFpT2gQ==", "dev": true, - "license": "MIT", "dependencies": { "get-intrinsic": "^1.2.4" }, @@ -61,7 +59,6 @@ "resolved": "https://registry.npmjs.org/es-errors/-/es-errors-1.3.0.tgz", "integrity": "sha512-Zf5H2Kxt2xjTvbJvP2ZWLEICxA6j+hAmMzIlypy4xcBg1vKVnx89Wy0GbS+kf5cwCVFFzdCFh2XSCFNULS6csw==", "dev": true, - "license": "MIT", "engines": { "node": ">= 0.4" } @@ -71,7 +68,6 @@ "resolved": "https://registry.npmjs.org/function-bind/-/function-bind-1.1.2.tgz", "integrity": "sha512-7XHNxH7qX9xG5mIwxkhumTox/MIRNcOgDrxWsMt2pAr23WHp6MrRlN7FBSFpCpr+oVO0F744iUgR82nJMfG2SA==", "dev": true, - "license": "MIT", "funding": { "url": "https://github.com/sponsors/ljharb" } @@ -81,7 +77,6 @@ "resolved": "https://registry.npmjs.org/get-intrinsic/-/get-intrinsic-1.2.4.tgz", "integrity": "sha512-5uYhsJH8VJBTv7oslg4BznJYhDoRI6waYCxMmCdnTrcCrHA/fCFKoTFz2JKKE0HdDFUF7/oQuhzumXJK7paBRQ==", "dev": true, - "license": "MIT", "dependencies": { "es-errors": "^1.3.0", "function-bind": "^1.1.2", @@ -101,7 +96,6 @@ "resolved": "https://registry.npmjs.org/gopd/-/gopd-1.0.1.tgz", "integrity": "sha512-d65bNlIadxvpb/A2abVdlqKqV563juRnZ1Wtk6s1sIR8uNsXR70xqIzVqxVf1eTqDunwT2MkczEeaezCKTZhwA==", "dev": true, - "license": "MIT", "dependencies": { "get-intrinsic": "^1.1.3" }, @@ -114,7 +108,6 @@ "resolved": "https://registry.npmjs.org/has-property-descriptors/-/has-property-descriptors-1.0.2.tgz", "integrity": "sha512-55JNKuIW+vq4Ke1BjOTjM2YctQIvCT7GFzHwmfZPGo5wnrgkid0YQtnAleFSqumZm4az3n2BS+erby5ipJdgrg==", "dev": true, - "license": "MIT", "dependencies": { "es-define-property": "^1.0.0" }, @@ -127,7 +120,6 @@ "resolved": "https://registry.npmjs.org/has-proto/-/has-proto-1.0.3.tgz", "integrity": "sha512-SJ1amZAJUiZS+PhsVLf5tGydlaVB8EdFpaSO4gmiUKUOxk8qzn5AIy4ZeJUmh22znIdk/uMAUT2pl3FxzVUH+Q==", "dev": true, - "license": "MIT", "engines": { "node": ">= 0.4" }, @@ -140,7 +132,6 @@ "resolved": "https://registry.npmjs.org/has-symbols/-/has-symbols-1.0.3.tgz", "integrity": "sha512-l3LCuF6MgDNwTDKkdYGEihYjt5pRPbEg46rtlmnSPlUbgmB8LOIrKJbYYFBSbnPaJexMKtiPO8hmeRjRz2Td+A==", "dev": true, - "license": "MIT", "engines": { "node": ">= 0.4" }, @@ -153,7 +144,6 @@ "resolved": "https://registry.npmjs.org/hasown/-/hasown-2.0.2.tgz", "integrity": "sha512-0hJU9SCPvmMzIBdZFqNPXWa6dqh7WdH0cII9y+CyS8rG3nL48Bclra9HmKhVVUHyPWNH5Y7xDwAB7bfgSjkUMQ==", "dev": true, - "license": "MIT", "dependencies": { "function-bind": "^1.1.2" }, @@ -166,7 +156,6 @@ "resolved": "https://registry.npmjs.org/object-keys/-/object-keys-1.1.1.tgz", "integrity": "sha512-NuAESUOUMrlIXOfHKzD6bpPu3tYt3xvjNdRIQ+FeT0lNb4K8WR70CaDxhuNguS2XG+GjkyMwOzsN5ZktImfhLA==", "dev": true, - "license": "MIT", "engines": { "node": ">= 0.4" } diff --git a/test/npm/define-properties/package.json b/test/npm/define-properties/package.json index 499f7232..bcb27b51 100644 --- a/test/npm/define-properties/package.json +++ b/test/npm/define-properties/package.json @@ -1,10 +1,10 @@ { "private": true, "scripts": { - "prepare": "patch-package", + "prepare": "patch-package && npm-recursive-install --skip-root --includeDirectories 'node_modules/define-properties'", "test": "tape 'node_modules/define-properties/test/**/*.js'" }, "devDependencies": { - "define-properties": "git://github.com/ljharb/define-properties.git#v1.2.1" + "define-properties": "https://github.com/ljharb/define-properties/archive/d7a4db30214eb06d3997dc3e662c11dfe95b25bd.tar.gz" } } diff --git a/test/npm/querystringify/index.js b/test/npm/querystringify/index.js new file mode 100644 index 00000000..39dcc67a --- /dev/null +++ b/test/npm/querystringify/index.js @@ -0,0 +1,3 @@ +'use strict' + +module.exports = require('@socketregistry/monorepo/packages/npm/querystringify') diff --git a/test/npm/querystringify/package-lock.json b/test/npm/querystringify/package-lock.json new file mode 100644 index 00000000..7238c733 --- /dev/null +++ b/test/npm/querystringify/package-lock.json @@ -0,0 +1,19 @@ +{ + "name": "querystringify", + "lockfileVersion": 3, + "requires": true, + "packages": { + "": { + "devDependencies": { + "querystringify": "https://github.com/unshiftio/querystringify/archive/73db95a504f988dce3f790e174e298ceb2b46a8e.tar.gz" + } + }, + "node_modules/querystringify": { + "version": "2.2.0", + "resolved": "https://github.com/unshiftio/querystringify/archive/73db95a504f988dce3f790e174e298ceb2b46a8e.tar.gz", + "integrity": "sha512-NKDxhxBX+WJpAkjw5xTxg84vmiwEvdVBZNVpxbyX17gQjS8T8mD3Nkb+TikyxQd5pVCyzB++H3TahgHnBRjE9g==", + "dev": true, + "license": "MIT" + } + } +} diff --git a/test/npm/querystringify/package.json b/test/npm/querystringify/package.json new file mode 100644 index 00000000..2a5a2d15 --- /dev/null +++ b/test/npm/querystringify/package.json @@ -0,0 +1,10 @@ +{ + "private": true, + "scripts": { + "prepare": "patch-package && npm-recursive-install --skip-root --includeDirectories 'node_modules/querystringify'", + "test": "node_modules/querystringify/node_modules/.bin/mocha 'node_modules/querystringify/test.js'" + }, + "devDependencies": { + "querystringify": "https://github.com/unshiftio/querystringify/archive/73db95a504f988dce3f790e174e298ceb2b46a8e.tar.gz" + } +} diff --git a/test/npm/querystringify/patches/querystringify+2.2.0.patch b/test/npm/querystringify/patches/querystringify+2.2.0.patch new file mode 100644 index 00000000..5874e9c6 --- /dev/null +++ b/test/npm/querystringify/patches/querystringify+2.2.0.patch @@ -0,0 +1,12 @@ +diff --git a/node_modules/querystringify/index.js b/node_modules/querystringify/index.js +index 58c9808..eee9b3b 100644 +--- a/node_modules/querystringify/index.js ++++ b/node_modules/querystringify/index.js +@@ -1,5 +1,7 @@ + 'use strict'; + ++module.exports = require(require('node:path').resolve(`${__dirname}/../../`)); ++return + var has = Object.prototype.hasOwnProperty + , undef; +