Skip to content

Commit

Permalink
v6.9.5
Browse files Browse the repository at this point in the history
  • Loading branch information
ljharb committed Jan 13, 2021
1 parent d4f6c32 commit 179fafc
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 25 deletions.
11 changes: 11 additions & 0 deletions CHANGELOG.md
@@ -1,3 +1,14 @@
## **6.9.5**
- [Fix] `stringify`: do not encode parens for RFC1738
- [Fix] `stringify`: fix arrayFormat comma with empty array/objects (#350)
- [Refactor] `format`: remove `util.assign` call
- [meta] add "Allow Edits" workflow; update rebase workflow
- [actions] switch Automatic Rebase workflow to `pull_request_target` event
- [Tests] `stringify`: add tests for #378
- [Tests] migrate tests to Github Actions
- [Tests] run `nyc` on all tests; use `tape` runner
- [Dev Deps] update `eslint`, `@ljharb/eslint-config`, `browserify`, `mkdirp`, `object-inspect`, `tape`; add `aud`

## **6.9.4**
- [Fix] `stringify`: when `arrayFormat` is `comma`, respect `serializeDate` (#364)
- [Refactor] `stringify`: reduce branching (part of #350)
Expand Down
55 changes: 31 additions & 24 deletions dist/qs.js
Expand Up @@ -4,29 +4,26 @@
var replace = String.prototype.replace;
var percentTwenties = /%20/g;

var util = require('./utils');

var Format = {
RFC1738: 'RFC1738',
RFC3986: 'RFC3986'
};

module.exports = util.assign(
{
'default': Format.RFC3986,
formatters: {
RFC1738: function (value) {
return replace.call(value, percentTwenties, '+');
},
RFC3986: function (value) {
return String(value);
}
module.exports = {
'default': Format.RFC3986,
formatters: {
RFC1738: function (value) {
return replace.call(value, percentTwenties, '+');
},
RFC3986: function (value) {
return String(value);
}
},
Format
);
RFC1738: Format.RFC1738,
RFC3986: Format.RFC3986
};

},{"./utils":5}],2:[function(require,module,exports){
},{}],2:[function(require,module,exports){
'use strict';

var stringify = require('./stringify');
Expand Down Expand Up @@ -182,7 +179,7 @@ var parseObject = function (chain, val, options, valuesParsed) {
}
}

leaf = obj; // eslint-disable-line no-param-reassign
leaf = obj;
}

return leaf;
Expand Down Expand Up @@ -366,6 +363,7 @@ var stringify = function stringify(
sort,
allowDots,
serializeDate,
format,
formatter,
encodeValuesOnly,
charset
Expand All @@ -381,21 +379,21 @@ var stringify = function stringify(
return serializeDate(value);
}
return value;
}).join(',');
});
}

if (obj === null) {
if (strictNullHandling) {
return encoder && !encodeValuesOnly ? encoder(prefix, defaults.encoder, charset, 'key') : prefix;
return encoder && !encodeValuesOnly ? encoder(prefix, defaults.encoder, charset, 'key', format) : prefix;
}

obj = '';
}

if (isNonNullishPrimitive(obj) || utils.isBuffer(obj)) {
if (encoder) {
var keyValue = encodeValuesOnly ? prefix : encoder(prefix, defaults.encoder, charset, 'key');
return [formatter(keyValue) + '=' + formatter(encoder(obj, defaults.encoder, charset, 'value'))];
var keyValue = encodeValuesOnly ? prefix : encoder(prefix, defaults.encoder, charset, 'key', format);
return [formatter(keyValue) + '=' + formatter(encoder(obj, defaults.encoder, charset, 'value', format))];
}
return [formatter(prefix) + '=' + formatter(String(obj))];
}
Expand All @@ -407,7 +405,10 @@ var stringify = function stringify(
}

var objKeys;
if (isArray(filter)) {
if (generateArrayPrefix === 'comma' && isArray(obj)) {
// we need to join elements in
objKeys = [{ value: obj.length > 0 ? obj.join(',') || null : undefined }];
} else if (isArray(filter)) {
objKeys = filter;
} else {
var keys = Object.keys(obj);
Expand All @@ -416,7 +417,7 @@ var stringify = function stringify(

for (var i = 0; i < objKeys.length; ++i) {
var key = objKeys[i];
var value = obj[key];
var value = typeof key === 'object' && key.value !== undefined ? key.value : obj[key];

if (skipNulls && value === null) {
continue;
Expand All @@ -437,6 +438,7 @@ var stringify = function stringify(
sort,
allowDots,
serializeDate,
format,
formatter,
encodeValuesOnly,
charset
Expand Down Expand Up @@ -484,6 +486,7 @@ var normalizeStringifyOptions = function normalizeStringifyOptions(opts) {
encoder: typeof opts.encoder === 'function' ? opts.encoder : defaults.encoder,
encodeValuesOnly: typeof opts.encodeValuesOnly === 'boolean' ? opts.encodeValuesOnly : defaults.encodeValuesOnly,
filter: filter,
format: format,
formatter: formatter,
serializeDate: typeof opts.serializeDate === 'function' ? opts.serializeDate : defaults.serializeDate,
skipNulls: typeof opts.skipNulls === 'boolean' ? opts.skipNulls : defaults.skipNulls,
Expand Down Expand Up @@ -549,6 +552,7 @@ module.exports = function (object, opts) {
options.sort,
options.allowDots,
options.serializeDate,
options.format,
options.formatter,
options.encodeValuesOnly,
options.charset
Expand All @@ -574,6 +578,8 @@ module.exports = function (object, opts) {
},{"./formats":1,"./utils":5}],5:[function(require,module,exports){
'use strict';

var formats = require('./formats');

var has = Object.prototype.hasOwnProperty;
var isArray = Array.isArray;

Expand Down Expand Up @@ -694,7 +700,7 @@ var decode = function (str, decoder, charset) {
}
};

var encode = function encode(str, defaultEncoder, charset) {
var encode = function encode(str, defaultEncoder, charset, kind, format) {
// This code was originally written by Brian White (mscdex) for the io.js core querystring library.
// It has been adapted here for stricter adherence to RFC 3986
if (str.length === 0) {
Expand Down Expand Up @@ -726,6 +732,7 @@ var encode = function encode(str, defaultEncoder, charset) {
|| (c >= 0x30 && c <= 0x39) // 0-9
|| (c >= 0x41 && c <= 0x5A) // a-z
|| (c >= 0x61 && c <= 0x7A) // A-Z
|| (format === formats.RFC1738 && (c === 0x28 || c === 0x29)) // ( )
) {
out += string.charAt(i);
continue;
Expand Down Expand Up @@ -821,5 +828,5 @@ module.exports = {
merge: merge
};

},{}]},{},[2])(2)
},{"./formats":1}]},{},[2])(2)
});
2 changes: 1 addition & 1 deletion package.json
Expand Up @@ -2,7 +2,7 @@
"name": "qs",
"description": "A querystring parser that supports nesting and arrays, with a depth limit",
"homepage": "https://github.com/ljharb/qs",
"version": "6.9.4",
"version": "6.9.5",
"repository": {
"type": "git",
"url": "https://github.com/ljharb/qs.git"
Expand Down

0 comments on commit 179fafc

Please sign in to comment.