File tree Expand file tree Collapse file tree 2 files changed +15
-1
lines changed Expand file tree Collapse file tree 2 files changed +15
-1
lines changed Original file line number Diff line number Diff line change 1+ import { substituteRepoOpenWithUrl } from './repo-common.ts' ;
2+
3+ test ( 'substituteRepoOpenWithUrl' , ( ) => {
4+ expect ( substituteRepoOpenWithUrl ( 'proto://a/{url}' , 'https://gitea' ) ) . toEqual ( 'proto://a/https://gitea' ) ;
5+ expect ( substituteRepoOpenWithUrl ( 'proto://a?link={url}' , 'https://gitea' ) ) . toEqual ( 'proto://a?link=https%3A%2F%2Fgitea' ) ;
6+ } ) ;
Original file line number Diff line number Diff line change @@ -42,6 +42,14 @@ export function initRepoActivityTopAuthorsChart() {
4242 }
4343}
4444
45+ export function substituteRepoOpenWithUrl ( tmpl : string , url : string ) : string {
46+ const pos = tmpl . indexOf ( '{url}' ) ;
47+ if ( pos === - 1 ) return tmpl ;
48+ const posQuestionMark = tmpl . indexOf ( '?' ) ;
49+ const needEncode = posQuestionMark >= 0 && posQuestionMark < pos ;
50+ return tmpl . replace ( '{url}' , needEncode ? encodeURIComponent ( url ) : url ) ;
51+ }
52+
4553function initCloneSchemeUrlSelection ( parent : Element ) {
4654 const elCloneUrlInput = parent . querySelector < HTMLInputElement > ( '.repo-clone-url' ) ;
4755
@@ -70,7 +78,7 @@ function initCloneSchemeUrlSelection(parent: Element) {
7078 }
7179 }
7280 for ( const el of parent . querySelectorAll < HTMLAnchorElement > ( '.js-clone-url-editor' ) ) {
73- el . href = el . getAttribute ( 'data-href-template' ) . replace ( '{url}' , encodeURIComponent ( link ) ) ;
81+ el . href = substituteRepoOpenWithUrl ( el . getAttribute ( 'data-href-template' ) , link ) ;
7482 }
7583 } ;
7684
You can’t perform that action at this time.
0 commit comments