Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: domain match routine #236

Merged
merged 1 commit into from Apr 21, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/cookie.js
Expand Up @@ -368,7 +368,7 @@ function domainMatch(str, domStr, canonicalize) {
/* " o All of the following [three] conditions hold:" */

/* "* The domain string is a suffix of the string" */
const idx = str.indexOf(domStr);
const idx = str.lastIndexOf(domStr);
if (idx <= 0) {
return false; // it's a non-match (-1) or prefix (0)
}
Expand Down
4 changes: 3 additions & 1 deletion test/domain_and_path_test.js
Expand Up @@ -33,7 +33,6 @@
const vows = require("vows");
const assert = require("assert");
const tough = require("../lib/cookie");
const Cookie = tough.Cookie;

function matchVows(func, table) {
const theVows = {};
Expand Down Expand Up @@ -105,6 +104,9 @@ vows
["www.aaaa.com", "aaa.com", false],
["www.aaa.com", "aaa.com", true],
["www.aexample.com", "example.com", false], // has to match on "." boundary
["computer.com", "com", true], // suffix string found at start of domain
["becoming.com", "com", true], // suffix string found in middle of domain
["sitcom.com", "com", true], // suffix string found just before the '.' boundary

// S5.1.3 "The string is a host name (i.e., not an IP address)"
["192.168.0.1", "168.0.1", false], // because str is an IP (v4)
Expand Down