mirror of
https://github.com/stablyai/orca.git
synced 2026-09-27 08:02:35 +00:00
fix: open localhost tab entry suffix urls (#4266)
This commit is contained in:
@@ -34,6 +34,21 @@ describe('tab create entry classification', () => {
|
||||
})
|
||||
})
|
||||
|
||||
it('opens local-dev URLs with root suffixes as browser tabs', () => {
|
||||
expect(classifyTabEntryQuery('localhost:3000/', readyFiles([]))).toEqual({
|
||||
kind: 'host-url',
|
||||
url: 'http://localhost:3000/'
|
||||
})
|
||||
expect(classifyTabEntryQuery('localhost:3000?debug=1', readyFiles([]))).toEqual({
|
||||
kind: 'host-url',
|
||||
url: 'http://localhost:3000/?debug=1'
|
||||
})
|
||||
expect(classifyTabEntryQuery('localhost:3000#preview', readyFiles([]))).toEqual({
|
||||
kind: 'host-url',
|
||||
url: 'http://localhost:3000/#preview'
|
||||
})
|
||||
})
|
||||
|
||||
it('keeps common source/document filenames as file candidates', () => {
|
||||
expect(classifyTabEntryQuery('README.md', readyFiles([]))).toEqual({
|
||||
kind: 'new-file',
|
||||
|
||||
@@ -19,6 +19,8 @@ const HOST_FILE_EXTENSIONS = new Set([
|
||||
'yaml',
|
||||
'yml'
|
||||
])
|
||||
const LOCAL_ADDRESS_PATTERN =
|
||||
/^(?:localhost|127(?:\.\d{1,3}){3}|0\.0\.0\.0|\[[0-9a-f:]+\])(?::\d+)?(?:[/?#].*)?$/i
|
||||
|
||||
export type TabEntryClassification =
|
||||
| { kind: 'empty'; message: string }
|
||||
@@ -110,6 +112,9 @@ function findExistingFileMatches(
|
||||
function classifyExplicitUrl(
|
||||
query: string
|
||||
): Extract<TabEntryClassification, { kind: 'blocked' | 'explicit-url' }> | null {
|
||||
if (LOCAL_ADDRESS_PATTERN.test(query)) {
|
||||
return null
|
||||
}
|
||||
let url: URL
|
||||
try {
|
||||
url = new URL(query)
|
||||
@@ -122,6 +127,20 @@ function classifyExplicitUrl(
|
||||
return { kind: 'explicit-url', url: url.href }
|
||||
}
|
||||
|
||||
function classifyLocalDevUrl(
|
||||
query: string
|
||||
): Extract<TabEntryActionClassification, { kind: 'host-url' }> | null {
|
||||
if (!LOCAL_ADDRESS_PATTERN.test(query)) {
|
||||
return null
|
||||
}
|
||||
try {
|
||||
const url = new URL(`http://${query}`)
|
||||
return url.hostname ? { kind: 'host-url', url: url.href } : null
|
||||
} catch {
|
||||
return null
|
||||
}
|
||||
}
|
||||
|
||||
function classifyHostLikeUrl(
|
||||
query: string
|
||||
): Extract<TabEntryActionClassification, { kind: 'host-url' }> | null {
|
||||
@@ -242,7 +261,7 @@ export function getTabEntryOptions(
|
||||
newFile = null
|
||||
}
|
||||
|
||||
const hostUrl = classifyHostLikeUrl(trimmed)
|
||||
const hostUrl = classifyLocalDevUrl(trimmed) ?? classifyHostLikeUrl(trimmed)
|
||||
|
||||
const options: TabEntryActionClassification[] = []
|
||||
if (exactExistingFiles.length > 0) {
|
||||
|
||||
Reference in New Issue
Block a user