@@ -2,7 +2,7 @@ import { css, html, LitElement } from 'lit';
22import { classMap } from 'lit/directives/class-map.js' ;
33import { ifDefined } from 'lit/directives/if-defined.js' ;
44import { iconRemixExternalLinkLine as externalLinkIcon , iconRemixDownloadLine } from '../../assets/cc-remix.icons.js' ;
5- import { isStringEmpty } from '../../lib/utils.js' ;
5+ import { isExternalUrl , isStringEmpty } from '../../lib/utils.js' ;
66import { skeletonStyles } from '../../styles/skeleton.js' ;
77import { i18n } from '../../translations/translation.js' ;
88import '../cc-icon/cc-icon.js' ;
@@ -83,24 +83,6 @@ export class CcLink extends LitElement {
8383 this . _title = '' ;
8484 }
8585
86- /**
87- * Checks if a given URL points to a different origin than the current page.
88- * If the URL is invalid, it is considered as a different origin for security.
89- *
90- * @param {string } rawUrl - The URL to check.
91- * @returns {boolean } True if the URL points to a different origin, false otherwise.
92- * @private
93- */
94- _isDifferentOrigin ( rawUrl ) {
95- try {
96- const url = new URL ( rawUrl , location . href ) ;
97- return url . origin !== location . origin ;
98- } catch {
99- // Consider bad URLs as different origin
100- return true ;
101- }
102- }
103-
10486 /**
10587 * Determines the appropriate title for the link
10688 *
@@ -140,7 +122,7 @@ export class CcLink extends LitElement {
140122
141123 render ( ) {
142124 const href = this . href != null && ! this . skeleton ? this . href : null ;
143- const isDifferentOrigin = this . _isDifferentOrigin ( href ) ;
125+ const isDifferentOrigin = isExternalUrl ( href ) ;
144126 const target = isDifferentOrigin ? '_blank' : null ;
145127 const rel = isDifferentOrigin ? 'noreferrer' : null ;
146128 const disableExternalIcon = this . disableExternalLinkIcon || this . mode !== 'default' ;
0 commit comments