From 1928b6a4e82401d9dc8a6dfc36a2be9d823b6813 Mon Sep 17 00:00:00 2001 From: riot Date: Fri, 17 Jan 2025 23:51:34 +0200 Subject: [PATCH 1/5] feat: update minimist to 1.2.8 because of proto polluting --- package-lock.json | 124 ++++++++++++++++++++++++++++++++++++++++++++++ package.json | 2 +- 2 files changed, 125 insertions(+), 1 deletion(-) create mode 100644 package-lock.json diff --git a/package-lock.json b/package-lock.json new file mode 100644 index 0000000..bd9194d --- /dev/null +++ b/package-lock.json @@ -0,0 +1,124 @@ +{ + "name": "@minimistjs/subarg", + "version": "1.0.0", + "lockfileVersion": 3, + "requires": true, + "packages": { + "": { + "name": "@minimistjs/subarg", + "version": "1.0.0", + "license": "MIT", + "dependencies": { + "minimist": "^1.2.8" + }, + "devDependencies": { + "tape": "^3.0.0" + } + }, + "node_modules/deep-equal": { + "version": "0.2.2", + "resolved": "https://registry.npmjs.org/deep-equal/-/deep-equal-0.2.2.tgz", + "integrity": "sha512-FXgye2Jr6oEk01S7gmSrHrPEQ1ontR7wwl+nYiZ8h4SXlHVm0DYda74BIPcHz2s2qPz4+375IcAz1vsWLwddgQ==", + "dev": true + }, + "node_modules/defined": { + "version": "0.0.0", + "resolved": "https://registry.npmjs.org/defined/-/defined-0.0.0.tgz", + "integrity": "sha512-zpqiCT8bODLu3QSmLLic8xJnYWBFjOSu/fBCm189oAiTtPq/PSanNACKZDS7kgSyCJY7P+IcODzlIogBK/9RBg==", + "dev": true + }, + "node_modules/glob": { + "version": "3.2.11", + "resolved": "https://registry.npmjs.org/glob/-/glob-3.2.11.tgz", + "integrity": "sha512-hVb0zwEZwC1FXSKRPFTeOtN7AArJcJlI6ULGLtrstaswKNlrTJqAA+1lYlSUop4vjA423xlBzqfVS3iWGlqJ+g==", + "deprecated": "Glob versions prior to v9 are no longer supported", + "dev": true, + "dependencies": { + "inherits": "2", + "minimatch": "0.3" + }, + "engines": { + "node": "*" + } + }, + "node_modules/inherits": { + "version": "2.0.4", + "resolved": "https://registry.npmjs.org/inherits/-/inherits-2.0.4.tgz", + "integrity": "sha512-k/vGaX4/Yla3WzyMCvTQOXYeIHvqOKtnqBduzTHpzpQZzAskKMhZ2K+EnBiSM9zGSoIFeMpXKxa4dYeZIQqewQ==", + "dev": true + }, + "node_modules/lru-cache": { + "version": "2.7.3", + "resolved": "https://registry.npmjs.org/lru-cache/-/lru-cache-2.7.3.tgz", + "integrity": "sha512-WpibWJ60c3AgAz8a2iYErDrcT2C7OmKnsWhIcHOjkUHFjkXncJhtLxNSqUmxRxRunpb5I8Vprd7aNSd2NtksJQ==", + "dev": true + }, + "node_modules/minimatch": { + "version": "0.3.0", + "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-0.3.0.tgz", + "integrity": "sha512-WFX1jI1AaxNTZVOHLBVazwTWKaQjoykSzCBNXB72vDTCzopQGtyP91tKdFK5cv1+qMwPyiTu1HqUriqplI8pcA==", + "deprecated": "Please update to minimatch 3.0.2 or higher to avoid a RegExp DoS issue", + "dev": true, + "dependencies": { + "lru-cache": "2", + "sigmund": "~1.0.0" + }, + "engines": { + "node": "*" + } + }, + "node_modules/minimist": { + "version": "1.2.8", + "resolved": "https://registry.npmjs.org/minimist/-/minimist-1.2.8.tgz", + "integrity": "sha512-2yyAR8qBkN3YuheJanUpWC5U3bb5osDywNB8RzDVlDwDHbocAJveqqj1u8+SVD7jkWT4yvsHCpWqqWqAxb0zCA==", + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, + "node_modules/object-inspect": { + "version": "0.4.0", + "resolved": "https://registry.npmjs.org/object-inspect/-/object-inspect-0.4.0.tgz", + "integrity": "sha512-8WvkvUZiKAjjsy/63rJjA7jw9uyF0CLVLjBKEfnPHE3Jxvs1LgwqL2OmJN+LliIX1vrzKW+AAu02Cc+xv27ncQ==", + "dev": true + }, + "node_modules/resumer": { + "version": "0.0.0", + "resolved": "https://registry.npmjs.org/resumer/-/resumer-0.0.0.tgz", + "integrity": "sha512-Fn9X8rX8yYF4m81rZCK/5VmrmsSbqS/i3rDLl6ZZHAXgC2nTAx3dhwG8q8odP/RmdLa2YrybDJaAMg+X1ajY3w==", + "dev": true, + "dependencies": { + "through": "~2.3.4" + } + }, + "node_modules/sigmund": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/sigmund/-/sigmund-1.0.1.tgz", + "integrity": "sha512-fCvEXfh6NWpm+YSuY2bpXb/VIihqWA6hLsgboC+0nl71Q7N7o2eaCW8mJa/NLvQhs6jpd3VZV4UiUQlV6+lc8g==", + "dev": true + }, + "node_modules/tape": { + "version": "3.6.1", + "resolved": "https://registry.npmjs.org/tape/-/tape-3.6.1.tgz", + "integrity": "sha512-Qy+shSMwr+bg5NwJhrdCKNOS7BEoo/SEjE+dF4a2OYR73f6ocH5ioLIHE6TuttjONmR3HYlOXwSqFTxUDFJtGg==", + "dev": true, + "dependencies": { + "deep-equal": "~0.2.0", + "defined": "~0.0.0", + "glob": "~3.2.9", + "inherits": "~2.0.1", + "object-inspect": "~0.4.0", + "resumer": "~0.0.0", + "through": "~2.3.4" + }, + "bin": { + "tape": "bin/tape" + } + }, + "node_modules/through": { + "version": "2.3.8", + "resolved": "https://registry.npmjs.org/through/-/through-2.3.8.tgz", + "integrity": "sha512-w89qg7PI8wAdvX60bMDP+bFoD5Dvhm9oLheFp5O4a2QF0cSBGsBX4qZmadPMvVqlLJBBci+WqGGOAPvcDeNSVg==", + "dev": true + } + } +} diff --git a/package.json b/package.json index 6beb0e6..89de609 100644 --- a/package.json +++ b/package.json @@ -4,7 +4,7 @@ "description": "parse arguments with recursive contexts", "main": "index.js", "dependencies": { - "minimist": "^1.1.0" + "minimist": "^1.2.8" }, "devDependencies": { "tape": "^3.0.0" From bdcf28572000ebfcafa310bd7ea9ceedb269f14c Mon Sep 17 00:00:00 2001 From: riot Date: Fri, 17 Jan 2025 23:51:48 +0200 Subject: [PATCH 2/5] chore: add .gitignore for the node_modules --- .gitignore | 1 + 1 file changed, 1 insertion(+) create mode 100644 .gitignore diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..b512c09 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +node_modules \ No newline at end of file From 512d784dafb1ee540b32e75100e9c68abaf053c0 Mon Sep 17 00:00:00 2001 From: riot Date: Mon, 20 Jan 2025 18:01:25 +0200 Subject: [PATCH 3/5] fix: inline closing bracket error --- index.js | 10 ++-- package.json | 2 +- test/inlineBrackets.js | 124 +++++++++++++++++++++++++++++++++++++++++ 3 files changed, 130 insertions(+), 6 deletions(-) create mode 100644 test/inlineBrackets.js diff --git a/index.js b/index.js index ca2c99d..d51ee6c 100644 --- a/index.js +++ b/index.js @@ -3,16 +3,16 @@ var minimist = require('minimist'); module.exports = function parse (args, opts) { var level = 0, index; var args_ = []; - + for (var i = 0; i < args.length; i++) { if (typeof args[i] === 'string' && /^\[/.test(args[i])) { if (level ++ === 0) { index = i; } } - if (typeof args[i] === 'string' && /\]$/.test(args[i])) { + if (typeof args[i] === 'string' && /^\[?[^\[]*\]$/.test(args[i])) { if (-- level > 0) continue; - + var sub = args.slice(index, i + 1); if (typeof sub[0] === 'string') { sub[0] = sub[0].replace(/^\[/, ''); @@ -24,12 +24,12 @@ module.exports = function parse (args, opts) { sub[n] = sub[n].replace(/\]$/, ''); } if (sub[n] === '') sub.pop(); - + args_.push(parse(sub)); } else if (level === 0) args_.push(args[i]); } - + var argv = minimist(args_, opts); return argv; }; diff --git a/package.json b/package.json index 89de609..b12645f 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@minimistjs/subarg", - "version": "1.0.0", + "version": "2.0.0", "description": "parse arguments with recursive contexts", "main": "index.js", "dependencies": { diff --git a/test/inlineBrackets.js b/test/inlineBrackets.js new file mode 100644 index 0000000..20feabc --- /dev/null +++ b/test/inlineBrackets.js @@ -0,0 +1,124 @@ +var subarg = require('..'); +var test = require('tape'); + +test('inline brackets', function (t) { + t.plan(6); + t.deepEqual( + subarg('beep -t [ boop -o a.txt -u http://localhost -u http://localhost\?q=\[1\] -q]'.split(/\s+/)), + { + _: [ 'beep'], + t: { + _: [ 'boop' ], + o: 'a.txt', + u: [ 'http://localhost', 'http://localhost?q=[1]' ], + q: true + } + } + ) + + t.deepEqual( + subarg('beep -t [boop -o a.txt -u http://localhost -u http://localhost\?q=\[1\] -q -o b.txt]'.split(/\s+/)), + { + _: [ 'beep'], + t: { + _: [ 'boop' ], + o: [ 'a.txt', 'b.txt' ], + u: [ 'http://localhost', 'http://localhost?q=[1]' ], + q: true + } + } + ) + + t.deepEqual( + subarg('beep -t [ boop -o a.txt -u http://localhost -u http://localhost\?q=\[1\] ]'.split(/\s+/)), + { + _: [ 'beep'], + t: { + _: [ 'boop' ], + o: 'a.txt', + u: [ 'http://localhost', 'http://localhost?q=[1]' ] + } + } + ) + + t.deepEqual( + subarg('beep -t [boop -o a.txt -u http://localhost\?q=\[1\] -u http://localhost]'.split(/\s+/)), + { + _: [ 'beep'], + t: { + _: [ 'boop' ], + o: 'a.txt', + u: [ 'http://localhost?q=[1]', 'http://localhost' ] + } + } + ) + + t.deepEqual( + subarg('beep -t [ boop -o a.txt -u [beep] ]'.split(/\s+/)), + { + _: [ 'beep'], + t: { + _: [ 'boop' ], + o: 'a.txt', + u: { + _: [ 'beep' ] + } + } + } + ) + + t.deepEqual( + subarg('beep -t [boop] -u [ be[ep] ]'.split(/\s+/)), + { + _: [ 'beep'], + t: { + _: [ 'boop' ] + }, + u: { + _: [ 'be[ep]' ] + } + } + ) +}); + +test.skip('doesnt work', function (t) { + t.plan(2); + /* + * expected: + * { _: [ 'beep' ], t: { _: [ 'boop' ], o: 'a.txt', u: [ 'http://localhost', 'http://localhost?q=[1]' ] } } + * actual: + * { _: [ 'beep' ], t: true } + * + */ + t.deepEqual( + subarg('beep -t [boop -o a.txt -u http://localhost -u http://localhost\?q=\[1\]]'.split(/\s+/)), + { + _: [ 'beep'], + t: { + _: [ 'boop' ], + o: 'a.txt', + u: [ 'http://localhost', 'http://localhost?q=[1]' ] + } + } + ) + + t.deepEqual( + subarg('beep -t [ boop -o a.txt -u [be[ep] ]'.split(/\s+/)), + { + /* + * expected: + * { _: [ 'beep' ], t: { _: [ 'boop' ], o: 'a.txt', u: { _: [ 'beep' ] } } } + * actual: + * { _: [ 'beep' ], t: true } + */ + _: [ 'beep'], + t: { + _: [ 'boop' ], + o: 'a.txt', + u: { + _: [ 'beep' ] + } + } + } + ) +}); From c286cdede2082ef85bcee43b45ea9aba3495698a Mon Sep 17 00:00:00 2001 From: riot Date: Mon, 20 Jan 2025 18:16:02 +0200 Subject: [PATCH 4/5] chose(test): add the buggy test case from the reporting issue --- test/inlineBrackets.js | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/test/inlineBrackets.js b/test/inlineBrackets.js index 20feabc..c4707fb 100644 --- a/test/inlineBrackets.js +++ b/test/inlineBrackets.js @@ -2,7 +2,15 @@ var subarg = require('..'); var test = require('tape'); test('inline brackets', function (t) { - t.plan(6); + t.plan(7); + + t.deepEqual( + subarg('http://localhost\?q=\[1\]'.split(/\s+/)), + { + _: [ 'http://localhost?q=[1]' ] + } + ) + t.deepEqual( subarg('beep -t [ boop -o a.txt -u http://localhost -u http://localhost\?q=\[1\] -q]'.split(/\s+/)), { From be8c04fe8fbe9dc34d48857f7f04f249c9534080 Mon Sep 17 00:00:00 2001 From: riot Date: Mon, 20 Jan 2025 18:42:08 +0200 Subject: [PATCH 5/5] chore(test): update test --- test/inlineBrackets.js | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/test/inlineBrackets.js b/test/inlineBrackets.js index c4707fb..2b23fae 100644 --- a/test/inlineBrackets.js +++ b/test/inlineBrackets.js @@ -111,11 +111,12 @@ test.skip('doesnt work', function (t) { ) t.deepEqual( - subarg('beep -t [ boop -o a.txt -u [be[ep] ]'.split(/\s+/)), + subarg('beep -t [ boop -o a.txt -u [ be[ep]] ]'.split(/\s+/)), { - /* + /* Same as above - note the context-closing bracket is right next to an inline closing bracket + * If you add a space, it works * expected: - * { _: [ 'beep' ], t: { _: [ 'boop' ], o: 'a.txt', u: { _: [ 'beep' ] } } } + * { _: [ 'beep' ], t: { _: [ 'boop' ], o: 'a.txt', u: { _: [ 'be[ep]' ] } } } * actual: * { _: [ 'beep' ], t: true } */ @@ -124,7 +125,7 @@ test.skip('doesnt work', function (t) { _: [ 'boop' ], o: 'a.txt', u: { - _: [ 'beep' ] + _: [ 'be[ep]' ] } } }