fix: accept bare browser addresses
The Browser workbar required users to enter a complete HTTP(S) URL, so submitting a bare domain or host with a port failed URL validation. Enter and Go now prepend http:// before using the existing browser navigation path. Explicit protocols remain unchanged so the Main browser URL policy continues to reject unsupported schemes with the correct error. Release note: 浏览器地址栏现在支持直接输入域名或主机端口,回车或点击“前往”时会自动补全 http://。
This commit is contained in:
@@ -9630,16 +9630,39 @@ describe('App', () => {
|
||||
expect(address).toHaveValue('https://example.com/start')
|
||||
|
||||
fireEvent.change(address, {
|
||||
target: { value: 'https://example.com/enter' }
|
||||
target: { value: 'example.com/enter' }
|
||||
})
|
||||
fireEvent.keyDown(address, { key: 'Enter' })
|
||||
await waitFor(() =>
|
||||
expect(api.browser.navigate).toHaveBeenLastCalledWith(
|
||||
expect.any(String),
|
||||
'https://example.com/enter'
|
||||
'http://example.com/enter'
|
||||
)
|
||||
)
|
||||
expect(api.browser.navigate).toHaveBeenCalledTimes(2)
|
||||
expect(address).toHaveValue('http://example.com/enter')
|
||||
|
||||
fireEvent.change(address, {
|
||||
target: { value: 'mailto:user@example.com' }
|
||||
})
|
||||
fireEvent.keyDown(address, { key: 'Enter' })
|
||||
await waitFor(() =>
|
||||
expect(api.browser.navigate).toHaveBeenLastCalledWith(
|
||||
expect.any(String),
|
||||
'mailto:user@example.com'
|
||||
)
|
||||
)
|
||||
|
||||
fireEvent.change(address, {
|
||||
target: { value: 'localhost:3000/path' }
|
||||
})
|
||||
fireEvent.keyDown(address, { key: 'Enter' })
|
||||
await waitFor(() =>
|
||||
expect(api.browser.navigate).toHaveBeenLastCalledWith(
|
||||
expect.any(String),
|
||||
'http://localhost:3000/path'
|
||||
)
|
||||
)
|
||||
expect(api.browser.navigate).toHaveBeenCalledTimes(4)
|
||||
})
|
||||
|
||||
it('suppresses duplicate browser actions while keeping stop loading available', async () => {
|
||||
|
||||
@@ -237,6 +237,18 @@ function measureSplitLayoutWidth(
|
||||
return measuredWidth > 0 ? measuredWidth : fallbackWidth
|
||||
}
|
||||
|
||||
function addDefaultBrowserProtocol(address: string): string {
|
||||
const protocol = /^[a-z][a-z\d+.-]*:/iu.exec(address)?.[0]
|
||||
if (
|
||||
protocol &&
|
||||
(/^https?:$/iu.test(protocol) ||
|
||||
!/^\d+(?:[/?#]|$)/u.test(address.slice(protocol.length)))
|
||||
) {
|
||||
return address
|
||||
}
|
||||
return `http://${address}`
|
||||
}
|
||||
|
||||
function BrowserToolbar({
|
||||
activeConversationId,
|
||||
browserState,
|
||||
@@ -325,10 +337,12 @@ function BrowserToolbar({
|
||||
}
|
||||
|
||||
const submitAddress = async (): Promise<void> => {
|
||||
const url = displayedAddress.trim()
|
||||
if (goDisabled || !url) {
|
||||
const address = displayedAddress.trim()
|
||||
if (goDisabled || !address) {
|
||||
return
|
||||
}
|
||||
const url = addDefaultBrowserProtocol(address)
|
||||
setAddressDraft(url)
|
||||
if (await runToolbarAction(() => onNavigate(url))) {
|
||||
setDirty(false)
|
||||
setEditing(false)
|
||||
|
||||
Reference in New Issue
Block a user