From da1eee03f599f3cdd802557874257091b3c4dac1 Mon Sep 17 00:00:00 2001 From: Jordan Harband Date: Sun, 9 Jan 2022 22:40:45 -0800 Subject: [PATCH] [Dev Deps] backport from main --- .editorconfig | 44 +++++++++++++++++++++ .eslintignore | 1 - .eslintrc | 30 +++++++++++--- .gitignore | 8 ++++ .npmignore | 18 +++++++-- .nycrc | 13 ++++++ README.md | 2 +- bower.json | 38 +++++++++--------- component.json | 26 ++++++------ lib/parse.js | 15 +++---- lib/stringify.js | 14 +++---- lib/utils.js | 20 ++++++---- package.json | 101 ++++++++++++++++++++++++----------------------- test/.eslintrc | 10 ----- test/parse.js | 4 +- 15 files changed, 215 insertions(+), 129 deletions(-) create mode 100644 .editorconfig delete mode 100644 .eslintignore create mode 100644 .nycrc delete mode 100644 test/.eslintrc diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 00000000..226a9322 --- /dev/null +++ b/.editorconfig @@ -0,0 +1,44 @@ +root = true + +[*] +indent_style = space +indent_size = 4 +end_of_line = lf +charset = utf-8 +trim_trailing_whitespace = true +insert_final_newline = true +max_line_length = 160 +quote_type = single + +[test/*] +max_line_length = off + +[*.md] +indent_size = off +max_line_length = off + +[*.json] +max_line_length = off + +[Makefile] +max_line_length = off + +[CHANGELOG.md] +indent_style = space +indent_size = 2 + +[LICENSE] +indent_size = 2 +max_line_length = off + +[coverage/**/*] +indent_size = off +indent_style = off +indent = off +max_line_length = off + +[dist/*] +max_line_length = off + +[.nycrc] +indent_style = tab diff --git a/.eslintignore b/.eslintignore deleted file mode 100644 index 1521c8b7..00000000 --- a/.eslintignore +++ /dev/null @@ -1 +0,0 @@ -dist diff --git a/.eslintrc b/.eslintrc index 98560175..cd5979ed 100644 --- a/.eslintrc +++ b/.eslintrc @@ -3,17 +3,35 @@ "extends": "@ljharb", + "ignorePatterns": [ + "dist/", + ], + "rules": { - "complexity": [2, 25], + "complexity": [2, 29], "consistent-return": 1, + "func-name-matching": 0, "id-length": [2, { "min": 1, "max": 25, "properties": "never" }], "indent": [2, 4], - "max-params": [2, 11], - "max-statements": [2, 42], - "no-extra-parens": 1, + "max-lines-per-function": 0, + "max-params": [2, 12], + "max-statements": [2, 45], + "multiline-comment-style": 0, "no-continue": 1, "no-magic-numbers": 0, + "no-param-reassign": 1, "no-restricted-syntax": [2, "BreakStatement", "DebuggerStatement", "ForInStatement", "LabeledStatement", "WithStatement"], - "operator-linebreak": 1 - } + }, + + "overrides": [ + { + "files": "test/**", + "rules": { + "max-lines-per-function": 0, + "max-statements": 0, + "no-extend-native": 0, + "function-paren-newline": 0, + }, + }, + ], } diff --git a/.gitignore b/.gitignore index 8cace31c..267da50e 100644 --- a/.gitignore +++ b/.gitignore @@ -18,3 +18,11 @@ lib-cov complexity.md tests.tap dist/* + +# Only apps should have lockfiles +yarn.lock +package-lock.json +npm-shrinkwrap.json + +.nyc_output/ +coverage/ diff --git a/.npmignore b/.npmignore index ac980d91..5fafe6be 100644 --- a/.npmignore +++ b/.npmignore @@ -1,4 +1,14 @@ -bower.json -component.json -.npmignore -.travis.yml +# gitignore +npm-debug.log +node_modules +.DS_Store + +# Only apps should have lockfiles +yarn.lock +package-lock.json +npm-shrinkwrap.json + +.nyc_output/ +coverage/ + +.github/workflows diff --git a/.nycrc b/.nycrc new file mode 100644 index 00000000..1d57cabe --- /dev/null +++ b/.nycrc @@ -0,0 +1,13 @@ +{ + "all": true, + "check-coverage": false, + "reporter": ["text-summary", "text", "html", "json"], + "lines": 86, + "statements": 85.93, + "functions": 82.43, + "branches": 76.06, + "exclude": [ + "coverage", + "dist" + ] +} diff --git a/README.md b/README.md index e6e32130..7d0b750a 100644 --- a/README.md +++ b/README.md @@ -424,7 +424,7 @@ assert.equal(nullsSkipped, 'a=b'); ### Dealing with special character sets -By default the encoding and decoding of characters is done in `utf-8`. If you +By default the encoding and decoding of characters is done in `utf-8`. If you wish to encode querystrings to a different character set (i.e. [Shift JIS](https://en.wikipedia.org/wiki/Shift_JIS)) you can use the [`qs-iconv`](https://github.com/martinheidegger/qs-iconv) library: diff --git a/bower.json b/bower.json index 44f05064..7a582762 100644 --- a/bower.json +++ b/bower.json @@ -1,21 +1,21 @@ { - "name": "qs", - "main": "dist/qs.js", - "homepage": "https://github.com/hapijs/qs", - "authors": [ - "Nathan LaFreniere " - ], - "description": "A querystring parser that supports nesting and arrays, with a depth limit", - "keywords": [ - "querystring", - "qs" - ], - "license": "BSD-3-Clause", - "ignore": [ - "**/.*", - "node_modules", - "bower_components", - "test", - "tests" - ] + "name": "qs", + "main": "dist/qs.js", + "homepage": "https://github.com/hapijs/qs", + "authors": [ + "Nathan LaFreniere " + ], + "description": "A querystring parser that supports nesting and arrays, with a depth limit", + "keywords": [ + "querystring", + "qs" + ], + "license": "BSD-3-Clause", + "ignore": [ + "**/.*", + "node_modules", + "bower_components", + "test", + "tests" + ] } diff --git a/component.json b/component.json index bbaf1344..a05aabd1 100644 --- a/component.json +++ b/component.json @@ -1,15 +1,15 @@ { - "name": "qs", - "repository": "hapijs/qs", - "description": "query-string parser / stringifier with nesting support", - "version": "6.3.2", - "keywords": ["querystring", "query", "parser"], - "main": "lib/index.js", - "scripts": [ - "lib/index.js", - "lib/parse.js", - "lib/stringify.js", - "lib/utils.js" - ], - "license": "BSD-3-Clause" + "name": "qs", + "repository": "hapijs/qs", + "description": "query-string parser / stringifier with nesting support", + "version": "6.3.2", + "keywords": ["querystring", "query", "parser"], + "main": "lib/index.js", + "scripts": [ + "lib/index.js", + "lib/parse.js", + "lib/stringify.js", + "lib/utils.js" + ], + "license": "BSD-3-Clause" } diff --git a/lib/parse.js b/lib/parse.js index 6eabc3c0..81e415cc 100644 --- a/lib/parse.js +++ b/lib/parse.js @@ -60,11 +60,11 @@ var parseObject = function parseObjectRecursive(chain, val, options) { if (!options.parseArrays && cleanRoot === '') { obj = { 0: val }; } else if ( - !isNaN(index) && - root !== cleanRoot && - String(index) === cleanRoot && - index >= 0 && - (options.parseArrays && index <= options.arrayLimit) + !isNaN(index) + && root !== cleanRoot + && String(index) === cleanRoot + && index >= 0 + && (options.parseArrays && index <= options.arrayLimit) ) { obj = []; obj[index] = parseObject(chain, val, options); @@ -98,10 +98,7 @@ var parseKeys = function parseQueryStringKeys(givenKey, val, options) { var keys = []; if (parent) { - /* - * If we aren't using plain objects, optionally prefix keys - * that would overwrite object prototype properties - */ + // If we aren't using plain objects, optionally prefix keys that would overwrite object prototype properties if (!options.plainObjects && has.call(Object.prototype, parent)) { if (!options.allowPrototypes) { return; diff --git a/lib/stringify.js b/lib/stringify.js index c89285f3..94429b84 100644 --- a/lib/stringify.js +++ b/lib/stringify.js @@ -4,13 +4,13 @@ var utils = require('./utils'); var formats = require('./formats'); var arrayPrefixGenerators = { - brackets: function brackets(prefix) { // eslint-disable-line func-name-matching + brackets: function brackets(prefix) { return prefix + '[]'; }, - indices: function indices(prefix, key) { // eslint-disable-line func-name-matching + indices: function indices(prefix, key) { return prefix + '[' + key + ']'; }, - repeat: function repeat(prefix) { // eslint-disable-line func-name-matching + repeat: function repeat(prefix) { return prefix; } }; @@ -27,14 +27,14 @@ var defaults = { delimiter: '&', encode: true, encoder: utils.encode, - serializeDate: function serializeDate(date) { // eslint-disable-line func-name-matching + serializeDate: function serializeDate(date) { return toISO.call(date); }, skipNulls: false, strictNullHandling: false }; -var stringify = function stringify( // eslint-disable-line func-name-matching +var stringify = function stringify( object, prefix, generateArrayPrefix, @@ -136,12 +136,12 @@ module.exports = function (object, opts) { var strictNullHandling = typeof options.strictNullHandling === 'boolean' ? options.strictNullHandling : defaults.strictNullHandling; var skipNulls = typeof options.skipNulls === 'boolean' ? options.skipNulls : defaults.skipNulls; var encode = typeof options.encode === 'boolean' ? options.encode : defaults.encode; - var encoder = encode ? (typeof options.encoder === 'function' ? options.encoder : defaults.encoder) : null; + var encoder = encode ? typeof options.encoder === 'function' ? options.encoder : defaults.encoder : null; var sort = typeof options.sort === 'function' ? options.sort : null; var allowDots = typeof options.allowDots === 'undefined' ? false : options.allowDots; var serializeDate = typeof options.serializeDate === 'function' ? options.serializeDate : defaults.serializeDate; if (typeof options.format === 'undefined') { - options.format = formats.default; + options.format = formats['default']; } else if (!Object.prototype.hasOwnProperty.call(formats.formatters, options.format)) { throw new TypeError('Unknown format option provided.'); } diff --git a/lib/utils.js b/lib/utils.js index 9095b9d1..b198ae98 100644 --- a/lib/utils.js +++ b/lib/utils.js @@ -99,13 +99,13 @@ exports.encode = function (str) { var c = string.charCodeAt(i); if ( - c === 0x2D || // - - c === 0x2E || // . - c === 0x5F || // _ - c === 0x7E || // ~ - (c >= 0x30 && c <= 0x39) || // 0-9 - (c >= 0x41 && c <= 0x5A) || // a-z - (c >= 0x61 && c <= 0x7A) // A-Z + c === 0x2D // - + || c === 0x2E // . + || c === 0x5F // _ + || c === 0x7E // ~ + || (c >= 0x30 && c <= 0x39) // 0-9 + || (c >= 0x41 && c <= 0x5A) // a-z + || (c >= 0x61 && c <= 0x7A) // A-Z ) { out += string.charAt(i); continue; @@ -128,7 +128,11 @@ exports.encode = function (str) { i += 1; c = 0x10000 + (((c & 0x3FF) << 10) | (string.charCodeAt(i) & 0x3FF)); - out += hexTable[0xF0 | (c >> 18)] + hexTable[0x80 | ((c >> 12) & 0x3F)] + hexTable[0x80 | ((c >> 6) & 0x3F)] + hexTable[0x80 | (c & 0x3F)]; // eslint-disable-line max-len + /* eslint operator-linebreak: [2, "before"] */ + out += hexTable[0xF0 | (c >> 18)] + + hexTable[0x80 | ((c >> 12) & 0x3F)] + + hexTable[0x80 | ((c >> 6) & 0x3F)] + + hexTable[0x80 | (c & 0x3F)]; } return out; diff --git a/package.json b/package.json index 61997d35..00a42b4d 100644 --- a/package.json +++ b/package.json @@ -1,51 +1,54 @@ { - "name": "qs", - "description": "A querystring parser that supports nesting and arrays, with a depth limit", - "homepage": "https://github.com/ljharb/qs", - "version": "6.3.2", - "repository": { - "type": "git", - "url": "https://github.com/ljharb/qs.git" - }, - "main": "lib/index.js", - "contributors": [ - { - "name": "Jordan Harband", - "email": "ljharb@gmail.com", - "url": "http://ljharb.codes" - } - ], - "keywords": [ - "querystring", - "qs" - ], - "engines": { - "node": ">=0.6" - }, - "dependencies": {}, - "devDependencies": { - "@ljharb/eslint-config": "^11.0.0", - "browserify": "^14.1.0", - "covert": "^1.1.0", - "eslint": "^3.17.0", - "evalmd": "^0.0.17", - "iconv-lite": "^0.4.15", - "mkdirp": "^0.5.1", - "parallelshell": "^2.0.0", - "qs-iconv": "^1.0.4", - "safe-publish-latest": "^1.1.1", - "safer-buffer": "^2.0.2", - "tape": "^4.6.3" - }, - "scripts": { - "prepublish": "safe-publish-latest && npm run dist", - "pretest": "npm run --silent readme && npm run --silent lint", - "test": "npm run --silent coverage", - "tests-only": "node test", - "readme": "evalmd README.md", - "lint": "eslint lib/*.js test/*.js", - "coverage": "covert test", - "dist": "mkdirp dist && browserify --standalone Qs lib/index.js > dist/qs.js" - }, - "license": "BSD-3-Clause" + "name": "qs", + "description": "A querystring parser that supports nesting and arrays, with a depth limit", + "homepage": "https://github.com/ljharb/qs", + "version": "6.3.2", + "repository": { + "type": "git", + "url": "https://github.com/ljharb/qs.git" + }, + "main": "lib/index.js", + "contributors": [ + { + "name": "Jordan Harband", + "email": "ljharb@gmail.com", + "url": "http://ljharb.codes" + } + ], + "keywords": [ + "querystring", + "qs" + ], + "engines": { + "node": ">=0.6" + }, + "devDependencies": { + "@ljharb/eslint-config": "^20.1.0", + "aud": "^1.1.5", + "browserify": "^16.5.2", + "eclint": "^2.8.1", + "eslint": "^8.6.0", + "evalmd": "^0.0.17", + "iconv-lite": "^0.4.24", + "in-publish": "^2.0.1", + "mkdirp": "^0.5.1", + "nyc": "^10.3.2", + "qs-iconv": "^1.0.4", + "safe-publish-latest": "^2.0.0", + "safer-buffer": "^2.1.2", + "tape": "^5.4.0" + }, + "scripts": { + "prepublishOnly": "safe-publish-latest && npm run dist", + "prepublish": "not-in-publish || npm run prepublishOnly", + "pretest": "npm run --silent readme && npm run --silent lint", + "test": "npm run --silent tests-only", + "tests-only": "nyc tape 'test/**/*.js'", + "posttest": "aud --production", + "readme": "evalmd README.md", + "postlint": "eclint check $(git ls-files | xargs find 2> /dev/null | grep -vE 'node_modules|\\.git')", + "lint": "eslint --ext=js,mjs .", + "dist": "mkdirp dist && browserify --standalone Qs lib/index.js > dist/qs.js" + }, + "license": "BSD-3-Clause" } diff --git a/test/.eslintrc b/test/.eslintrc deleted file mode 100644 index 1b6df617..00000000 --- a/test/.eslintrc +++ /dev/null @@ -1,10 +0,0 @@ -{ - "rules": { - "consistent-return": 2, - "max-lines": 0, - "max-nested-callbacks": [2, 3], - "max-statements": 0, - "no-extend-native": 0, - "sort-keys": 1 - } -} diff --git a/test/parse.js b/test/parse.js index a90739b9..9aaf67ad 100644 --- a/test/parse.js +++ b/test/parse.js @@ -480,7 +480,7 @@ test('parse()', function (t) { st.deepEqual( qs.parse('a[b]=c&a=toString', { plainObjects: true }), - { a: { b: 'c', toString: true } }, + { __proto__: null, a: { __proto__: null, b: 'c', toString: true } }, 'can overwrite prototype with plainObjects true' ); @@ -519,7 +519,7 @@ test('parse()', function (t) { }); t.test('throws error with wrong decoder', function (st) { - st.throws(function () { + st['throws'](function () { qs.parse({}, { decoder: 'string' }); }, new TypeError('Decoder has to be a function.')); st.end();