fix: allow spaces in browser file paths (#3886)

This commit is contained in:
Jinwoo Hong 2026-05-30 15:59:07 -04:00 committed by GitHub
parent c5789ecc90
commit 09392af48b
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 14 additions and 2 deletions

View File

@ -50,6 +50,18 @@ describe('browser-url helpers', () => {
).toBe('file://wsl.localhost/Ubuntu/home/me/Example.ipynb')
})
it('normalizes absolute local paths with spaces and reserved URL characters', () => {
expect(normalizeBrowserNavigationUrl('/Users/me/My Site/index #1.html')).toBe(
'file:///Users/me/My%20Site/index%20%231.html'
)
expect(normalizeBrowserNavigationUrl('C:\\Users\\me\\My Site\\index #1.html')).toBe(
'file:///C:/Users/me/My%20Site/index%20%231.html'
)
expect(normalizeBrowserNavigationUrl('C:\\tmp\\orca & 100% ! ^\\index.html')).toBe(
'file:///C:/tmp/orca%20%26%20100%25%20!%20%5E/index.html'
)
})
// Why: in-app preview is fine (sandboxed webview), but handing file:// to
// shell.openExternal would let a remote page drive Finder/Explorer to
// arbitrary paths. External-open paths must still refuse file://.

View File

@ -8,9 +8,9 @@ const LOCAL_ADDRESS_PATTERN =
// A single-word input containing a dot with a valid TLD-like suffix is treated as
// a URL attempt, not a search query.
const LOOKS_LIKE_URL_PATTERN = /^[^\s]+\.[a-z]{2,}(\/.*)?$/i
const WINDOWS_ABSOLUTE_PATH_PATTERN = /^[A-Za-z]:[\\/][^\s]*$/
const WINDOWS_ABSOLUTE_PATH_PATTERN = /^[A-Za-z]:[\\/].*$/
const WINDOWS_UNC_PATH_PATTERN = /^\\\\[^\s\\/]+[\\/][^\\/]+(?:[\\/].*)?$/
const UNIX_ABSOLUTE_PATH_PATTERN = /^\/[^\s]*$/
const UNIX_ABSOLUTE_PATH_PATTERN = /^\/.*$/
export type SearchEngine = 'google' | 'duckduckgo' | 'bing' | 'kagi'