@@ -9,19 +9,35 @@ export const host = () => {
9
9
10
10
export const protocolAndHost = ( ) => `${ location . protocol } //${ host ( ) } ` ;
11
11
12
+ export const newSandboxUrl = ( ) => `/s/new` ;
13
+
14
+ const sandboxGitUrl = ( git : {
15
+ repo : string ,
16
+ branch : string ,
17
+ username : string ,
18
+ path : string ,
19
+ } ) =>
20
+ 'github/' + // eslint-disable-line prefer-template
21
+ encodeURIComponent ( git . username ) +
22
+ '/' +
23
+ encodeURIComponent ( git . repo ) +
24
+ '/tree/' +
25
+ encodeURIComponent ( git . branch ) +
26
+ '/' +
27
+ encodeURIComponent ( git . path ) ;
28
+
12
29
export const sandboxUrl = ( sandbox : Sandbox ) => {
13
30
if ( sandbox . git ) {
14
31
const { git } = sandbox ;
15
- return `/s/github/ ${ git . username } / ${ git . repo } /tree/ ${ git . branch } / ${ git . path } ` ;
32
+ return `/s/${ sandboxGitUrl ( git ) } ` ;
16
33
}
17
34
18
35
return `/s/${ sandbox . id } ` ;
19
36
} ;
20
- export const newSandboxUrl = ( ) => `/s/new` ;
21
37
export const embedUrl = ( sandbox : Sandbox ) => {
22
38
if ( sandbox . git ) {
23
39
const { git } = sandbox ;
24
- return `/embed/github/ ${ git . username } / ${ git . repo } /tree/ ${ git . branch } / ${ git . path } ` ;
40
+ return `/embed/${ sandboxGitUrl ( git ) } ` ;
25
41
}
26
42
27
43
return `/embed/${ sandbox . id } ` ;
@@ -60,9 +76,11 @@ export const githubRepoUrl = ({
60
76
61
77
export const optionsToParameterizedUrl = ( options : Object ) => {
62
78
const keyValues = Object . keys ( options )
63
- . map ( key => `${ key } =${ options [ key ] } ` )
79
+ . sort ( )
80
+ . map (
81
+ key => `${ encodeURIComponent ( key ) } =${ encodeURIComponent ( options [ key ] ) } ` ,
82
+ )
64
83
. join ( '&' ) ;
65
84
66
- if ( keyValues . length === 0 ) return '' ;
67
- return `?${ keyValues } ` ;
85
+ return keyValues ? `?${ keyValues } ` : '' ;
68
86
} ;
0 commit comments