Skip to content

Commit 9b10131

Browse files
authored
Merge pull request #236 from salesforce/fix/235_domain_matching
fix: domain match routine
2 parents 30246e6 + 35b7a13 commit 9b10131

File tree

2 files changed

+4
-2
lines changed

2 files changed

+4
-2
lines changed

lib/cookie.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -368,7 +368,7 @@ function domainMatch(str, domStr, canonicalize) {
368368
/* " o All of the following [three] conditions hold:" */
369369

370370
/* "* The domain string is a suffix of the string" */
371-
const idx = str.indexOf(domStr);
371+
const idx = str.lastIndexOf(domStr);
372372
if (idx <= 0) {
373373
return false; // it's a non-match (-1) or prefix (0)
374374
}

test/domain_and_path_test.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@
3333
const vows = require("vows");
3434
const assert = require("assert");
3535
const tough = require("../lib/cookie");
36-
const Cookie = tough.Cookie;
3736

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

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

0 commit comments

Comments
 (0)