forked from vitejs/vite
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: allow
localhost
as a valid hostname (vitejs#7075)
- Loading branch information
Showing
2 changed files
with
49 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,40 +1,58 @@ | ||
import { injectQuery, isWindows } from '../utils' | ||
import { injectQuery, isWindows, resolveHostname } from '../utils' | ||
|
||
if (isWindows) { | ||
// this test will work incorrectly on unix systems | ||
test('normalize windows path', () => { | ||
expect(injectQuery('C:\\User\\Vite\\Project', 'direct')).toEqual( | ||
'C:/User/Vite/Project?direct' | ||
describe('injectQuery', () => { | ||
if (isWindows) { | ||
// this test will work incorrectly on unix systems | ||
test('normalize windows path', () => { | ||
expect(injectQuery('C:\\User\\Vite\\Project', 'direct')).toEqual( | ||
'C:/User/Vite/Project?direct' | ||
) | ||
}) | ||
} | ||
|
||
test('path with multiple spaces', () => { | ||
expect(injectQuery('/usr/vite/path with space', 'direct')).toEqual( | ||
'/usr/vite/path with space?direct' | ||
) | ||
}) | ||
} | ||
|
||
test('path with multiple spaces', () => { | ||
expect(injectQuery('/usr/vite/path with space', 'direct')).toEqual( | ||
'/usr/vite/path with space?direct' | ||
) | ||
}) | ||
test('path with multiple % characters', () => { | ||
expect(injectQuery('/usr/vite/not%20a%20space', 'direct')).toEqual( | ||
'/usr/vite/not%20a%20space?direct' | ||
) | ||
}) | ||
|
||
test('path with multiple % characters', () => { | ||
expect(injectQuery('/usr/vite/not%20a%20space', 'direct')).toEqual( | ||
'/usr/vite/not%20a%20space?direct' | ||
) | ||
}) | ||
test('path with %25', () => { | ||
expect(injectQuery('/usr/vite/%25hello%25', 'direct')).toEqual( | ||
'/usr/vite/%25hello%25?direct' | ||
) | ||
}) | ||
|
||
test('path with %25', () => { | ||
expect(injectQuery('/usr/vite/%25hello%25', 'direct')).toEqual( | ||
'/usr/vite/%25hello%25?direct' | ||
) | ||
}) | ||
test('path with unicode', () => { | ||
expect(injectQuery('/usr/vite/東京', 'direct')).toEqual( | ||
'/usr/vite/東京?direct' | ||
) | ||
}) | ||
|
||
test('path with unicode', () => { | ||
expect(injectQuery('/usr/vite/東京', 'direct')).toEqual( | ||
'/usr/vite/東京?direct' | ||
) | ||
test('path with unicode, space, and %', () => { | ||
expect(injectQuery('/usr/vite/東京 %20 hello', 'direct')).toEqual( | ||
'/usr/vite/東京 %20 hello?direct' | ||
) | ||
}) | ||
}) | ||
|
||
test('path with unicode, space, and %', () => { | ||
expect(injectQuery('/usr/vite/東京 %20 hello', 'direct')).toEqual( | ||
'/usr/vite/東京 %20 hello?direct' | ||
) | ||
describe('resolveHostname', () => { | ||
test('defaults to 127.0.0.1', () => { | ||
expect(resolveHostname(undefined)).toEqual({ | ||
host: '127.0.0.1', | ||
name: 'localhost' | ||
}) | ||
}) | ||
|
||
test('accepts localhost', () => { | ||
expect(resolveHostname('localhost')).toEqual({ | ||
host: 'localhost', | ||
name: 'localhost' | ||
}) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters