File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1212 </div >
1313 <!-- open link -->
1414 <NcButton
15- :title =" t('text', 'Open link')"
16- :aria-label =" t('text', 'Open link')"
15+ :disabled =" !isSafeHref"
16+ :title =" openLinkTitle"
17+ :aria-label =" openLinkTitle"
1718 variant =" tertiary"
1819 @click =" openLink(href)" >
1920 <template #icon >
@@ -101,6 +102,7 @@ import { useOpenLinkHandler } from '../../composables/useOpenLinkHandler.ts'
101102import PreviewOptions from ' ../Editor/PreviewOptions.vue'
102103
103104const PROTOCOLS_WITH_PREVIEW = [' http:' , ' https:' ]
105+ const SAFE_PROTOCOLS = [' http:' , ' https:' , ' mailto:' , ' tel:' ]
104106
105107export default {
106108 name: ' LinkBubbleView' ,
@@ -170,6 +172,27 @@ export default {
170172 return false
171173 }
172174 },
175+
176+ isSafeHref () {
177+ try {
178+ const url = new URL (this .href , window .location )
179+ return !! this .href && SAFE_PROTOCOLS .includes (url .protocol )
180+ } catch {
181+ return false
182+ }
183+ },
184+
185+ openLinkTitle () {
186+ if (this .isSafeHref ) {
187+ return t (' text' , ' Open link' )
188+ }
189+
190+ if (! this .href ) {
191+ return t (' text' , ' No link available to open' )
192+ }
193+
194+ return t (' text' , ' Cannot open links with unsafe protocols' )
195+ },
173196 },
174197
175198 watch: {
You can’t perform that action at this time.
0 commit comments