Update load.ts
This commit is contained in:
		 Acid Chicken (硫酸鶏)
					Acid Chicken (硫酸鶏)
				
			
				
					committed by
					
						 GitHub
						GitHub
					
				
			
			
				
	
			
			
			 GitHub
						GitHub
					
				
			
						parent
						
							8b71006fbe
						
					
				
				
					commit
					cf9e8ed39e
				
			| @@ -47,14 +47,21 @@ export default function load() { | |||||||
| 	return Object.assign(config, mixin); | 	return Object.assign(config, mixin); | ||||||
| } | } | ||||||
|  |  | ||||||
| function validateUrl(url: string) { | function tryCreateUrl(url: string) { | ||||||
| 	try { | 	try { | ||||||
| 		return new URL(url); | 		return new URL(url); | ||||||
| 	} catch (e) { | 	} catch (e) { | ||||||
| 		throw `url="${url}" is not a valid URL`; | 		throw `url="${url}" is not a valid URL.`; | ||||||
| 	} | 	} | ||||||
| } | } | ||||||
|  |  | ||||||
|  | function validateUrl(url: string) { | ||||||
|  | 	const result = tryCreateUrl(url); | ||||||
|  | 	if (result.pathname.trim('/').length) throw `url="${url}" is not a valid URL, has a pathname.`; | ||||||
|  | 	if (!url.includes(result.host)) throw `url="${url}" is not a valid URL, has an invalid hostname.`; | ||||||
|  | 	return result; | ||||||
|  | } | ||||||
|  |  | ||||||
| function normalizeUrl(url: string) { | function normalizeUrl(url: string) { | ||||||
| 	return url.endsWith('/') ? url.substr(0, url.length - 1) : url; | 	return url.endsWith('/') ? url.substr(0, url.length - 1) : url; | ||||||
| } | } | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user