import { ITagHandler , TagNode } from '@cc98/ubb-core' ; import { IContext } from '@cc98/context' ; import React from 'react' ; import URL from 'url-parse' ; export function isSafe ( dangerousURL ) { if ( dangerousURL . length && dangerousURL [ 0 ] === '/' ) return true ; const url = URL ( dangerousURL . trim ( ) , { } ) ; if ( url . protocol === 'http:' ) return true ; if ( url . protocol === 'https:' ) return true ; return false ; } const handler = { isRecursive : true , render ( node , context , children ) { const innerText = node . innerText ; const dangerousURL = node . tagData . url || innerText ; const safeURL = isSafe ( dangerousURL ) ? dangerousURL : undefined ; return < a href = { safeURL } > { children } < /a>; } , } ; export default handler ;