Skip to content

Commit a312820

Browse files
committed
Fix regression bug in domainMatch
The code in `domainMatch` needs to make comparisions using the `_str` and `_domStr` variables as these are canonicalized versions of the `domain` and `cookieDomain` arguments. One of the comparisions was mistakenly using the `cookieDomain` when it should have been using `_domStr`. This PR closes #499 by using the correct variable for the comparison and adds a test that covers this case to our list of cases for `domainMatch`.
1 parent 9328fc4 commit a312820

File tree

2 files changed

+4
-1
lines changed

2 files changed

+4
-1
lines changed

lib/__tests__/domainMatch.spec.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,9 @@ describe('domainMatch', () => {
7474
['🫠.com', 'xn--129h.com', true], // Emoji!
7575
['ρһіѕһ.info', 'xn--2xa01ac71bc.info', true], // Greek + Cyrillic characters
7676
['猫.cat', 'xn--z7x.cat', true], // Japanese characters
77+
78+
// domain that needs to be canonicalized
79+
['www.google.com', '.google.com', true],
7780
])('domainMatch(%s, %s) => %s', (string, domain, expectedValue) => {
7881
expect(domainMatch(string, domain)).toBe(expectedValue)
7982
})

lib/cookie/domainMatch.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ export function domainMatch(
8484
/* " o All of the following [three] conditions hold:" */
8585

8686
/* "* The domain string is a suffix of the string" */
87-
const idx = _str.lastIndexOf(cookieDomain)
87+
const idx = _str.lastIndexOf(_domStr)
8888
if (idx <= 0) {
8989
return false // it's a non-match (-1) or prefix (0)
9090
}

0 commit comments

Comments
 (0)