Skip to content

Commit

Permalink
Merge pull request #236 from salesforce/fix/235_domain_matching
Browse files Browse the repository at this point in the history
fix: domain match routine
  • Loading branch information
colincasey authored Apr 21, 2022
2 parents 30246e6 + 35b7a13 commit 9b10131
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
2 changes: 1 addition & 1 deletion lib/cookie.js
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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

0 comments on commit 9b10131

Please sign in to comment.