mirror of
https://github.com/oceanprotocol/market.git
synced 2024-12-02 05:57:29 +01:00
parent
92b7063b3d
commit
228ff19056
9
src/@utils/url.test.ts
Normal file
9
src/@utils/url.test.ts
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
import { sanitizeUrl } from './url'
|
||||||
|
|
||||||
|
describe('@utils/url', () => {
|
||||||
|
test('sanitizeUrl', () => {
|
||||||
|
expect(sanitizeUrl('http://example.com')).toBe('http://example.com')
|
||||||
|
expect(sanitizeUrl('https://example.com')).toBe('https://example.com')
|
||||||
|
expect(sanitizeUrl('ftp://example.com')).toBe('about:blank')
|
||||||
|
})
|
||||||
|
})
|
@ -1,10 +1,5 @@
|
|||||||
export function sanitizeUrl(url: string) {
|
export function sanitizeUrl(url: string) {
|
||||||
const u = decodeURI(url).trim().toLowerCase()
|
const u = decodeURI(url).trim().toLowerCase()
|
||||||
if (
|
const isAllowedUrlScheme = u.startsWith('http://') || u.startsWith('https://')
|
||||||
u.startsWith('javascript:') ||
|
return isAllowedUrlScheme ? url : 'about:blank'
|
||||||
u.startsWith('data:') ||
|
|
||||||
u.startsWith('vbscript:')
|
|
||||||
)
|
|
||||||
return 'about:blank'
|
|
||||||
return url
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user