File tree Expand file tree Collapse file tree
ui/scripts/components/presentations Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -3,6 +3,7 @@ import { createElement as h } from 'react'
33
44import Favicon from '../Favicon.js'
55
6+ import faviconUrl from '../../../../utils/faviconUrl.js'
67import enhanceUrl from '../../enhancers/enhanceUrl.js'
78import sumByProp from '../../utils/sumByProp.js'
89
@@ -95,7 +96,7 @@ const PresentationIconList = (props) => {
9596
9697 return h ( UrlRow , {
9798 ...commonProps ,
98- faviconUrl : new URL ( '/favicon.ico' , item . url ) . href ,
99+ faviconUrl : faviconUrl ( item . url ) ,
99100 url : item . url ,
100101 } )
101102 } ) ,
Original file line number Diff line number Diff line change 1+ const localhostRegex = / ( ^ | \. ) l o c a l h o s t $ / i
2+ const loopbackRegex = / ^ 1 2 7 (?: \. \d { 1 , 3 } ) { 3 } $ /
3+
4+ const isLocalHostname = ( hostname ) => {
5+ return localhostRegex . test ( hostname ) === true || loopbackRegex . test ( hostname ) === true || hostname === '[::1]'
6+ }
7+
8+ export default ( url ) => {
9+ if ( url == null || isLocalHostname ( url . hostname ) === true ) return
10+
11+ return new URL ( '/favicon.ico' , url ) . href
12+ }
Original file line number Diff line number Diff line change 1+ import test from 'ava'
2+
3+ import faviconUrl from '../../src/utils/faviconUrl.js'
4+
5+ test ( 'return favicon URL for public hostnames' , ( t ) => {
6+ const result = faviconUrl ( new URL ( 'https://example.com/path' ) )
7+
8+ t . is ( result , 'https://example.com/favicon.ico' )
9+ } )
10+
11+ test ( 'return nothing for localhost hostname' , ( t ) => {
12+ const result = faviconUrl ( new URL ( 'http://localhost:5173/path' ) )
13+
14+ t . is ( result , undefined )
15+ } )
16+
17+ test ( 'return nothing for localhost subdomains' , ( t ) => {
18+ const result = faviconUrl ( new URL ( 'http://app.localhost:5173/path' ) )
19+
20+ t . is ( result , undefined )
21+ } )
22+
23+ test ( 'return nothing for IPv4 loopback hostname' , ( t ) => {
24+ const result = faviconUrl ( new URL ( 'http://127.0.0.1:5173/path' ) )
25+
26+ t . is ( result , undefined )
27+ } )
28+
29+ test ( 'return nothing for IPv6 loopback hostname' , ( t ) => {
30+ const result = faviconUrl ( new URL ( 'http://[::1]:5173/path' ) )
31+
32+ t . is ( result , undefined )
33+ } )
You can’t perform that action at this time.
0 commit comments