Skip to content

Commit cf6debd

Browse files
committed
Fix incorrect string validation for URL
1 parent b1a8898 commit cf6debd

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
@@ -59,6 +59,14 @@ function isInstanceStrict(data, prototype) {
5959
}
6060
}
6161

62+
function isUrlStringOrObject(data) {
63+
return (
64+
isNonEmptyString(data) ||
65+
isObject(data) || // TODO: Check for URL properties that are used.
66+
isInstanceStrict(data, URL)
67+
);
68+
}
69+
6270
function isInteger(data) {
6371
return typeof data === "number" && data % 1 === 0;
6472
}
@@ -92,4 +100,5 @@ exports.isDate = isDate;
92100
exports.isEmptyString = isEmptyString;
93101
exports.isString = isString;
94102
exports.isObject = isObject;
103+
exports.isUrlStringOrObject = isUrlStringOrObject;
95104
exports.validate = validate;

0 commit comments

Comments
 (0)