Skip to content

Commit 50e69bf

Browse files
authored
Merge pull request #261 from postmanlabs/fix/url-string-validation
Fix incorrect string validation for URL
2 parents 1253d58 + cf6debd commit 50e69bf

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
lines changed

lib/cookie.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1116,7 +1116,8 @@ class CookieJar {
11161116
}
11171117

11181118
setCookie(cookie, url, options, cb) {
1119-
validators.validate(validators.isNonEmptyString(url), cb, options);
1119+
validators.validate(validators.isUrlStringOrObject(url), cb, options);
1120+
11201121
let err;
11211122

11221123
if (validators.isFunction(url)) {
@@ -1314,7 +1315,8 @@ class CookieJar {
13141315

13151316
// RFC6365 S5.4
13161317
getCookies(url, options, cb) {
1317-
validators.validate(validators.isNonEmptyString(url), cb, url);
1318+
validators.validate(validators.isUrlStringOrObject(url), cb, url);
1319+
13181320
const context = getCookieContext(url);
13191321
if (validators.isFunction(options)) {
13201322
cb = options;

lib/validators.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,14 @@ function isInstanceStrict(data, prototype) {
6262
}
6363
}
6464

65+
function isUrlStringOrObject(data) {
66+
return (
67+
isNonEmptyString(data) ||
68+
isObject(data) || // TODO: Check for URL properties that are used.
69+
isInstanceStrict(data, URL)
70+
);
71+
}
72+
6573
function isInteger(data) {
6674
return typeof data === "number" && data % 1 === 0;
6775
}
@@ -95,4 +103,5 @@ exports.isDate = isDate;
95103
exports.isEmptyString = isEmptyString;
96104
exports.isString = isString;
97105
exports.isObject = isObject;
106+
exports.isUrlStringOrObject = isUrlStringOrObject;
98107
exports.validate = validate;

0 commit comments

Comments
 (0)