Skip to content

Commit

Permalink
Merge pull request #261 from postmanlabs/fix/url-string-validation
Browse files Browse the repository at this point in the history
Fix incorrect string validation for URL
  • Loading branch information
colincasey authored Apr 26, 2024
2 parents 1253d58 + cf6debd commit 50e69bf
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
6 changes: 4 additions & 2 deletions lib/cookie.js
Original file line number Diff line number Diff line change
Expand Up @@ -1116,7 +1116,8 @@ class CookieJar {
}

setCookie(cookie, url, options, cb) {
validators.validate(validators.isNonEmptyString(url), cb, options);
validators.validate(validators.isUrlStringOrObject(url), cb, options);

let err;

if (validators.isFunction(url)) {
Expand Down Expand Up @@ -1314,7 +1315,8 @@ class CookieJar {

// RFC6365 S5.4
getCookies(url, options, cb) {
validators.validate(validators.isNonEmptyString(url), cb, url);
validators.validate(validators.isUrlStringOrObject(url), cb, url);

const context = getCookieContext(url);
if (validators.isFunction(options)) {
cb = options;
Expand Down
9 changes: 9 additions & 0 deletions lib/validators.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,14 @@ function isInstanceStrict(data, prototype) {
}
}

function isUrlStringOrObject(data) {
return (
isNonEmptyString(data) ||
isObject(data) || // TODO: Check for URL properties that are used.
isInstanceStrict(data, URL)
);
}

function isInteger(data) {
return typeof data === "number" && data % 1 === 0;
}
Expand Down Expand Up @@ -95,4 +103,5 @@ exports.isDate = isDate;
exports.isEmptyString = isEmptyString;
exports.isString = isString;
exports.isObject = isObject;
exports.isUrlStringOrObject = isUrlStringOrObject;
exports.validate = validate;

0 comments on commit 50e69bf

Please sign in to comment.