postman-request
Advanced tools
Comparing version 2.79.1-postman.1 to 2.79.1-postman.2
@@ -8,3 +8,2 @@ var url = require('url') | ||
, QUESTION_MARK = '?' | ||
, ENCODE_REGEX = /[!'()*]/g | ||
, stringify | ||
@@ -18,8 +17,32 @@ , parse | ||
(hex.length === 1) && (hex = '0' + hex) | ||
return '%' + hex | ||
return PERCENT + hex | ||
} | ||
isPreEncoded = function isPreEncoded(buffer, i) { | ||
// If it is % check next two bytes for percent encode characters | ||
// looking for pattern %00 - %FF | ||
return (buffer[i] === 0x25 && | ||
(isPreEncodedCharacter(buffer[i+1]) && | ||
isPreEncodedCharacter(buffer[i+2])) | ||
) | ||
} | ||
isPreEncodedCharacter = function isPreEncodedCharacter(byte) { | ||
return (byte >= 0x30 && byte <= 0x39) || // 0-9 | ||
(byte >= 0x41 && byte <= 0x46) || // A-F | ||
(byte >= 0x61 && byte <= 0x66) // a-f | ||
} | ||
charactersToPercentEncode = function charactersToPercentEncode(byte) { | ||
return (byte < 0x23 || byte > 0x7E || // Below # and after ~ | ||
byte === 0x3C || byte === 0x3E || // > and < | ||
byte === 0x28 || byte === 0x29 || // ( and ) | ||
byte === 0x25 || // % | ||
byte === 0x27 || // ' | ||
byte === 0x2A // * | ||
) | ||
} | ||
/** | ||
* Percent encodes a query string according to RFC 3986 | ||
* Percent partialEncode a query string according to RFC 3986 | ||
* | ||
@@ -29,3 +52,3 @@ * @param value | ||
*/ | ||
encode = function (value) { | ||
partialEncode = function (value) { | ||
if (!value) { return '' } | ||
@@ -38,4 +61,4 @@ | ||
for (i = 0; i < buffer.length; ++i) { | ||
if (buffer[i] < 0x21 || buffer[i] > 0x7E || buffer[i] === 0x22 || buffer[i] === 0x23 || | ||
buffer[i] === 0x3C || buffer[i] === 0x3E) { | ||
if (charactersToPercentEncode(buffer[i]) && !isPreEncoded(buffer, i)) { | ||
ret += percentEncode(buffer[i]) | ||
@@ -48,5 +71,2 @@ } else { | ||
return ret | ||
.replace(ENCODE_REGEX, function (c) { | ||
return PERCENT + c.charCodeAt(0).toString(16).toUpperCase() | ||
}) | ||
} | ||
@@ -97,11 +117,5 @@ | ||
return parameters ? parameters.map(function (param) { | ||
var key | ||
, value | ||
var key = param.key | ||
, value = param.value | ||
try { key = param.key && decodeURIComponent(param.key) } | ||
catch (e) { key = param.key } | ||
try { value = param.value && decodeURIComponent(param.value) } | ||
catch (e) { value = param.value } | ||
if (value === undefined) { | ||
@@ -116,6 +130,6 @@ return '' | ||
if (value === null) { | ||
return encode(key) | ||
return partialEncode(key) | ||
} | ||
return encode(key) + EQUALS + encode(value) | ||
return partialEncode(key) + EQUALS + partialEncode(value) | ||
}).join(AMPERSAND) : '' | ||
@@ -122,0 +136,0 @@ } |
@@ -10,3 +10,3 @@ { | ||
], | ||
"version": "2.79.1-postman.1", | ||
"version": "2.79.1-postman.2", | ||
"repository": { | ||
@@ -13,0 +13,0 @@ "type": "git", |
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
199219
2611