-
-
Notifications
You must be signed in to change notification settings - Fork 350
Commit
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,21 +16,10 @@ import { slice } from './slice.js' | |
import { assert, assertUsage } from './assert.js' | ||
import pc from '@brillout/picocolors' | ||
|
||
const PROTOCOLS = [ | ||
'http://', | ||
'https://', | ||
// For [Tauri](https://tauri.app/) | ||
'tauri://', | ||
// For Electron: https://github.com/vikejs/vike/issues/1557 | ||
'file://', | ||
// For Capacitor: https://github.com/vikejs/vike/issues/1706 | ||
'capacitor://' | ||
] | ||
|
||
function isParsable(url: string): boolean { | ||
// `parseUrl()` works with these URLs | ||
return ( | ||
PROTOCOLS.some((p) => url.startsWith(p)) || | ||
isUrlWithProtocol(url) || | ||
url.startsWith('/') || | ||
url.startsWith('.') || | ||
url.startsWith('?') || | ||
|
@@ -172,7 +161,7 @@ function getPathname(url: string, baseServer: string): { origin: null | string; | |
} | ||
|
||
function parseOrigin(url: string): { pathname: string; origin: null | string } { | ||
if (!PROTOCOLS.some((protocol) => url.startsWith(protocol))) { | ||
if (!isUrlWithProtocol(url)) { | ||
return { pathname: url, origin: null } | ||
} else { | ||
const [originPart1, originPart2, originPart3, ...pathnameParts] = url.split('/') | ||
|
@@ -294,3 +283,12 @@ function isUriWithProtocol(uri: string): boolean { | |
// https://en.wikipedia.org/wiki/List_of_URI_schemes | ||
return /^[a-z0-9][a-z0-9\.\+\-]*:/i.test(uri) | ||
} | ||
|
||
function isUrlWithProtocol(url: string) { | ||
// http:// | ||
// https:// | ||
// tauri:// # For [Tauri](https://tauri.app/) | ||
// file:// # For Electron: https://github.com/vikejs/vike/issues/1557 | ||
// capacitor:// # For Capacitor: https://github.com/vikejs/vike/issues/1706 | ||
return /[a-z]+\:\/\//i.test(url) | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
pdanpdan
|
||
} |
1 comment
on commit 886a99f
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I checked the url schemes and this regex matches the registered/official ones and the unofficial ones.
- Digits
+
shows up in composed schemes-
shows mostly in Microsoft ones.
is possible but discouraged in rfc, and I haven't seen it used
I would go with "start with letter and allow letter or digit after" - I can think of s3