postman-collection
Advanced tools
Comparing version 3.6.0-beta.3 to 3.6.0
@@ -14,9 +14,92 @@ var _ = require('../util').lodash, | ||
EMPTY = '', | ||
HASH = '#', | ||
BRACE_START = '{{', | ||
BRACE_END = '}}', | ||
REGEX_HASH = /#/g, | ||
REGEX_EQUALS = /=/g, // eslint-disable-line no-div-regex | ||
REGEX_AMPERSAND = /&/g, | ||
REGEX_BRACE_START = /%7B%7B/g, | ||
REGEX_BRACE_END = /%7D%7D/g, | ||
REGEX_EXTRACT_VARS = /{{[^{}]*[&#=][^{}]*}}/g, | ||
QueryParam; | ||
QueryParam, | ||
/** | ||
* Percent encode reserved chars (&, = and #) in the given string. | ||
* | ||
* @private | ||
* @param {String} str | ||
* @param {Boolean} encodeEquals | ||
* @returns {String} | ||
*/ | ||
encodeReservedChars = function (str, encodeEquals) { | ||
if (!str) { | ||
return str; | ||
} | ||
// eslint-disable-next-line lodash/prefer-includes | ||
str.indexOf(AMPERSAND) !== -1 && (str = str.replace(REGEX_AMPERSAND, '%26')); | ||
// eslint-disable-next-line lodash/prefer-includes | ||
str.indexOf(HASH) !== -1 && (str = str.replace(REGEX_HASH, '%23')); | ||
// eslint-disable-next-line lodash/prefer-includes | ||
encodeEquals && str.indexOf(EQUALS) !== -1 && (str = str.replace(REGEX_EQUALS, '%3D')); | ||
return str; | ||
}, | ||
/** | ||
* Normalize the given param string by percent-encoding the reserved chars | ||
* such that it won't affect the re-parsing. | ||
* | ||
* @note `&`, `=` and `#` needs to be percent-encoded otherwise re-parsing | ||
* the same URL string will generate different output | ||
* | ||
* @private | ||
* @param {String} str | ||
* @param {Boolean} encodeEquals | ||
* @returns {String} | ||
*/ | ||
normalizeParam = function (str, encodeEquals) { | ||
// bail out if the given sting is null or empty | ||
if (!(str && typeof str === STRING)) { | ||
return str; | ||
} | ||
// bail out if the given string does not include reserved chars | ||
// eslint-disable-next-line lodash/prefer-includes | ||
if (str.indexOf(AMPERSAND) === -1 && str.indexOf(HASH) === -1) { | ||
// eslint-disable-next-line lodash/prefer-includes | ||
if (!(encodeEquals && str.indexOf(EQUALS) !== -1)) { | ||
return str; | ||
} | ||
} | ||
var normalizedString = '', | ||
pointer = 0, | ||
variable, | ||
match, | ||
index; | ||
// find all the instances of {{<variable>}} which includes reserved chars | ||
while ((match = REGEX_EXTRACT_VARS.exec(str)) !== null) { | ||
variable = match[0]; | ||
index = match.index; | ||
// [pointer, index) string is normalized + the matched variable | ||
normalizedString += encodeReservedChars(str.slice(pointer, index), encodeEquals) + variable; | ||
// update the pointer | ||
pointer = index + variable.length; | ||
} | ||
// whatever left in the string is normalized as well | ||
if (pointer < str.length) { | ||
normalizedString += encodeReservedChars(str.slice(pointer), encodeEquals); | ||
} | ||
return normalizedString; | ||
}; | ||
/** | ||
@@ -211,3 +294,3 @@ * @typedef QueryParam~definition | ||
if (typeof key === STRING) { | ||
result = encode ? encodeQueryParam(key) : key; | ||
result = encode ? encodeQueryParam(key) : normalizeParam(key, true); | ||
} | ||
@@ -219,3 +302,3 @@ else { | ||
if (typeof value === STRING) { | ||
result += EQUALS + (encode ? encodeQueryParam(value) : value); | ||
result += EQUALS + (encode ? encodeQueryParam(value) : normalizeParam(value)); | ||
} | ||
@@ -222,0 +305,0 @@ |
@@ -5,3 +5,3 @@ { | ||
"author": "Postman Labs <help@getpostman.com>", | ||
"version": "3.6.0-beta.3", | ||
"version": "3.6.0", | ||
"keywords": [ | ||
@@ -77,3 +77,3 @@ "postman" | ||
"postman-jsdoc-theme": "0.0.3", | ||
"postman-request": "2.88.1-postman.18", | ||
"postman-request": "2.88.1-postman.19", | ||
"puppeteer": "1.20.0", | ||
@@ -80,0 +80,0 @@ "recursive-readdir": "2.2.2", |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
543500
11805
0