File tree Expand file tree Collapse file tree 2 files changed +20
-2
lines changed
components/gitpod-protocol/src Expand file tree Collapse file tree 2 files changed +20
-2
lines changed Original file line number Diff line number Diff line change @@ -24,6 +24,12 @@ export class ContextUrlTest {
24
24
expect ( actual ?. pathname ) . to . equal ( "/gitpod-io/gitpod-test-repo" ) ;
25
25
}
26
26
27
+ @test public parseContextUrl_withEnvVar_sshUrl ( ) {
28
+ const actual = ContextURL . parseToURL ( "passedin=test%20value/[email protected] :gitpod-io/gitpod-test-repo.git" ) ;
29
+ expect ( actual ?. host ) . to . equal ( "github.com" ) ;
30
+ expect ( actual ?. pathname ) . to . equal ( "/gitpod-io/gitpod-test-repo.git" ) ;
31
+ }
32
+
27
33
@test public parseContextUrl_withPrebuild ( ) {
28
34
const actual = ContextURL . parseToURL ( "prebuild/https://github.com/gitpod-io/gitpod-test-repo" ) ;
29
35
expect ( actual ?. host ) . to . equal ( "github.com" ) ;
@@ -35,5 +41,10 @@ export class ContextUrlTest {
35
41
expect ( actual ?. host ) . to . equal ( "github.com" ) ;
36
42
expect ( actual ?. pathname ) . to . equal ( "/gitpod-io/gitpod-test-repo" ) ;
37
43
}
44
+
45
+ @test public parseContextUrl_badUrl ( ) {
46
+ const actual = ContextURL . parseToURL ( "[Object object]" ) ;
47
+ expect ( actual ) . to . be . undefined ;
48
+ }
38
49
}
39
50
module . exports = new ContextUrlTest ( )
Original file line number Diff line number Diff line change @@ -26,12 +26,19 @@ export namespace ContextURL {
26
26
return new URL ( segments [ 0 ] ) ; // this might be something, we just try
27
27
}
28
28
29
- const segmentsToURL = ( offset : number ) : URL => {
29
+ const segmentsToURL = ( offset : number ) : URL | undefined => {
30
30
let rest = segments . slice ( offset ) . join ( "/" ) ;
31
+ if ( / ^ g i t @ [ ^ : \/ ] + : / . test ( rest ) ) {
32
+ rest = rest . replace ( / ^ g i t @ ( [ ^ : \/ ] + ) : / , 'https://$1/' ) ;
33
+ }
31
34
if ( ! rest . startsWith ( "http" ) ) {
32
35
rest = 'https://' + rest ;
33
36
}
34
- return new URL ( rest ) ;
37
+ try {
38
+ return new URL ( rest ) ;
39
+ } catch ( error ) {
40
+ console . error ( 'Could not parse context URL' , rest , error ) ;
41
+ }
35
42
} ;
36
43
37
44
You can’t perform that action at this time.
0 commit comments