fix(url): fix omnibox URL detection for dumb:// scheme
- commit
- 0ede461f611d4fcd770c1319ca22ebdd0ccb9e08
- author
- brice · · 2025-12-22 06:18 UTC
- parent
- b0d67b5
- signature
- unsigned
2 files · +23 -0
M internal/domain/url/normalize.go +16 -0
| @@ -37,10 +37,26 @@ func Normalize(input string) string { | |||
| 37 | 37 | ||
| 38 | 38 | // LooksLikeURL checks if the input appears to be a URL (not a search query). | |
| 39 | 39 | // Returns true for strings like "github.com", "google.com/search", etc. | |
| 40 | + | // Also returns true for URLs with explicit schemes like "dumb://". | |
| 40 | 41 | func LooksLikeURL(input string) bool { | |
| 41 | 42 | if input == "" { | |
| 42 | 43 | return false | |
| 43 | 44 | } | |
| 45 | + | ||
| 46 | + | // Explicit schemes should always be treated as URLs. | |
| 47 | + | switch { | |
| 48 | + | case strings.HasPrefix(input, "http://"): | |
| 49 | + | return true | |
| 50 | + | case strings.HasPrefix(input, "https://"): | |
| 51 | + | return true | |
| 52 | + | case strings.HasPrefix(input, "dumb://"): | |
| 53 | + | return true | |
| 54 | + | case strings.HasPrefix(input, "file://"): | |
| 55 | + | return true | |
| 56 | + | case strings.HasPrefix(input, "about:"): | |
| 57 | + | return true | |
| 58 | + | } | |
| 59 | + | ||
| 44 | 60 | // Contains a dot and no spaces = likely a URL | |
| 45 | 61 | return strings.Contains(input, ".") && !strings.Contains(input, " ") | |
| 46 | 62 | } | |
| @@ -37,10 +37,26 @@ func Normalize(input string) string { | |||||
| 37 | 37 | ||||
| 38 | // LooksLikeURL checks if the input appears to be a URL (not a search query). | 38 | // LooksLikeURL checks if the input appears to be a URL (not a search query). | ||
| 39 | // Returns true for strings like "github.com", "google.com/search", etc. | 39 | // Returns true for strings like "github.com", "google.com/search", etc. | ||
| 40 | + | // Also returns true for URLs with explicit schemes like "dumb://". | |||
| 40 | func LooksLikeURL(input string) bool { | 41 | func LooksLikeURL(input string) bool { | ||
| 41 | if input == "" { | 42 | if input == "" { | ||
| 42 | return false | 43 | return false | ||
| 43 | } | 44 | } | ||
| 45 | + | ||||
| 46 | + | // Explicit schemes should always be treated as URLs. | |||
| 47 | + | switch { | |||
| 48 | + | case strings.HasPrefix(input, "http://"): | |||
| 49 | + | return true | |||
| 50 | + | case strings.HasPrefix(input, "https://"): | |||
| 51 | + | return true | |||
| 52 | + | case strings.HasPrefix(input, "dumb://"): | |||
| 53 | + | return true | |||
| 54 | + | case strings.HasPrefix(input, "file://"): | |||
| 55 | + | return true | |||
| 56 | + | case strings.HasPrefix(input, "about:"): | |||
| 57 | + | return true | |||
| 58 | + | } | |||
| 59 | + | ||||
| 44 | // Contains a dot and no spaces = likely a URL | 60 | // Contains a dot and no spaces = likely a URL | ||
| 45 | return strings.Contains(input, ".") && !strings.Contains(input, " ") | 61 | return strings.Contains(input, ".") && !strings.Contains(input, " ") | ||
| 46 | } | 62 | } | ||
M internal/domain/url/search_test.go +7 -0
| @@ -69,6 +69,13 @@ func TestBuildSearchURL(t *testing.T) { | |||
| 69 | 69 | defaultSearch: testDefaultSearch, | |
| 70 | 70 | want: "https://example.com", | |
| 71 | 71 | }, | |
| 72 | + | { | |
| 73 | + | name: "custom scheme dumb unchanged", | |
| 74 | + | input: "dumb://settings", | |
| 75 | + | shortcuts: testShortcuts, | |
| 76 | + | defaultSearch: testDefaultSearch, | |
| 77 | + | want: "dumb://settings", | |
| 78 | + | }, | |
| 72 | 79 | { | |
| 73 | 80 | name: "plain search query uses default", | |
| 74 | 81 | input: "how to parse json", | |
| @@ -69,6 +69,13 @@ func TestBuildSearchURL(t *testing.T) { | |||||
| 69 | defaultSearch: testDefaultSearch, | 69 | defaultSearch: testDefaultSearch, | ||
| 70 | want: "https://example.com", | 70 | want: "https://example.com", | ||
| 71 | }, | 71 | }, | ||
| 72 | + | { | |||
| 73 | + | name: "custom scheme dumb unchanged", | |||
| 74 | + | input: "dumb://settings", | |||
| 75 | + | shortcuts: testShortcuts, | |||
| 76 | + | defaultSearch: testDefaultSearch, | |||
| 77 | + | want: "dumb://settings", | |||
| 78 | + | }, | |||
| 72 | { | 79 | { | ||
| 73 | name: "plain search query uses default", | 80 | name: "plain search query uses default", | ||
| 74 | input: "how to parse json", | 81 | input: "how to parse json", | ||