Skip to content

Commit a821c56

Browse files
authored
fix: use OR operator in includesCredentials per WHATWG URL Standard (#4816)
1 parent b3326b5 commit a821c56

File tree

2 files changed

+25
-1
lines changed

2 files changed

+25
-1
lines changed

lib/web/fetch/util.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1439,7 +1439,7 @@ function hasAuthenticationEntry (request) {
14391439
*/
14401440
function includesCredentials (url) {
14411441
// A URL includes credentials if its username or password is not the empty string.
1442-
return !!(url.username && url.password)
1442+
return !!(url.username || url.password)
14431443
}
14441444

14451445
/**

test/fetch/includes-credentials.js

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
'use strict'
2+
3+
const { test } = require('node:test')
4+
const { includesCredentials } = require('../../lib/web/fetch/util')
5+
6+
test('includesCredentials returns true for URL with both username and password', () => {
7+
const url = new URL('http://user:pass@example.com')
8+
require('node:assert').strictEqual(includesCredentials(url), true)
9+
})
10+
11+
test('includesCredentials returns true for URL with only username', () => {
12+
const url = new URL('http://user@example.com')
13+
require('node:assert').strictEqual(includesCredentials(url), true)
14+
})
15+
16+
test('includesCredentials returns true for URL with only password', () => {
17+
const url = new URL('http://:pass@example.com')
18+
require('node:assert').strictEqual(includesCredentials(url), true)
19+
})
20+
21+
test('includesCredentials returns false for URL with no credentials', () => {
22+
const url = new URL('http://example.com')
23+
require('node:assert').strictEqual(includesCredentials(url), false)
24+
})

0 commit comments

Comments
 (0)