@@ -66,12 +66,17 @@ export type Props = Partial<KuiConfiguration> & {
66
66
/** If in popup mode, execute the given command line */
67
67
commandLine ?: string [ ]
68
68
69
+ /** do not echo the command? */
70
+ quietExecCommand ?: boolean
71
+
69
72
/** initial tab title */
70
73
initialTabTitle ?: string
71
74
}
72
75
73
76
type State = KuiConfiguration & {
74
77
isBootstrapped : boolean
78
+ commandLine ?: string [ ]
79
+ quietExecCommand ?: boolean
75
80
}
76
81
77
82
/**
@@ -112,17 +117,39 @@ export class Kui extends React.PureComponent<Props, State> {
112
117
} )
113
118
}
114
119
120
+ let commandLine = this . props . commandLine
121
+ let quietExecCommand = this . props . quietExecCommand !== undefined ? this . props . quietExecCommand : ! this . props . isPopup
122
+
123
+ if ( inBrowser ( ) ) {
124
+ const windowQuery = window . location . search
125
+ if ( windowQuery ) {
126
+ // parse and extract the question mark in window.location.search
127
+ // e.g. query = { command: 'replay /kui/welcome.json' }
128
+ const query = require ( 'querystring' ) . parse ( windowQuery . substring ( 1 ) )
129
+
130
+ // To avoid SQL injection attacks, users can only query with `replay` command
131
+ if ( query . command && / ^ r e p l a y / . test ( query . command ) ) {
132
+ commandLine = query . command . split ( ' ' )
133
+ quietExecCommand = false
134
+ }
135
+ }
136
+ }
137
+
115
138
try {
116
139
this . state = Object . assign ( { } , this . defaultSessionBehavior ( ) , this . defaultFeatureFlag ( ) , props , {
117
- isBootstrapped : ! ! props . noBootstrap
140
+ isBootstrapped : ! ! props . noBootstrap ,
141
+ commandLine,
142
+ quietExecCommand
118
143
} )
119
144
debug ( 'initial state:inBrowser?' , inBrowser ( ) )
120
145
debug ( 'initial state:given properties' , props )
121
146
debug ( 'initial state:final value' , this . state )
122
147
} catch ( err ) {
123
148
console . log ( 'using default configuration' )
124
149
this . state = {
125
- isBootstrapped : ! ! props . noBootstrap
150
+ isBootstrapped : ! ! props . noBootstrap ,
151
+ commandLine,
152
+ quietExecCommand
126
153
}
127
154
}
128
155
}
@@ -220,8 +247,8 @@ export class Kui extends React.PureComponent<Props, State> {
220
247
*
221
248
*/
222
249
private statusStripeProps ( ) : StatusStripeProps {
223
- if ( this . props . commandLine ) {
224
- const statusStripeIdx = this . props . commandLine . findIndex ( _ => _ === '--status-stripe' )
250
+ if ( this . state . commandLine ) {
251
+ const statusStripeIdx = this . state . commandLine . findIndex ( _ => _ === '--status-stripe' )
225
252
if ( statusStripeIdx >= 0 ) {
226
253
return { type : this . props . commandLine [ statusStripeIdx + 1 ] as StatusStripeProps [ 'type' ] }
227
254
}
@@ -234,13 +261,14 @@ export class Kui extends React.PureComponent<Props, State> {
234
261
235
262
private firstTab = true
236
263
private onTabReady ( ) {
237
- if ( this . props . commandLine && this . firstTab ) {
264
+ if ( this . state . commandLine && this . firstTab ) {
238
265
this . firstTab = false
239
266
240
- // do not echo the command?
241
- const quiet = ! this . props . isPopup
242
-
243
- pexecInCurrentTab ( this . props . commandLine . map ( _ => encodeComponent ( _ ) ) . join ( ' ' ) , undefined , quiet )
267
+ pexecInCurrentTab (
268
+ this . state . commandLine . map ( _ => encodeComponent ( _ ) ) . join ( ' ' ) ,
269
+ undefined ,
270
+ this . state . quietExecCommand
271
+ )
244
272
}
245
273
}
246
274
@@ -251,11 +279,11 @@ export class Kui extends React.PureComponent<Props, State> {
251
279
return < Loading />
252
280
}
253
281
254
- if ( this . props . isPopup && this . props . commandLine ) {
282
+ if ( this . props . isPopup && this . state . commandLine ) {
255
283
return (
256
284
< KuiContext . Provider value = { this . state } >
257
285
< React . Suspense fallback = { < div /> } >
258
- < Popup commandLine = { this . props . commandLine } > { this . props . children } </ Popup >
286
+ < Popup commandLine = { this . state . commandLine } > { this . props . children } </ Popup >
259
287
</ React . Suspense >
260
288
</ KuiContext . Provider >
261
289
)
@@ -268,7 +296,7 @@ export class Kui extends React.PureComponent<Props, State> {
268
296
noActiveInput = { ! ! this . props . bottomInput }
269
297
bottom = { bottom }
270
298
title = { this . props . initialTabTitle }
271
- onTabReady = { this . props . commandLine && this . _onTabReady }
299
+ onTabReady = { this . state . commandLine && this . _onTabReady }
272
300
>
273
301
< ComboSidecar />
274
302
</ TabContainer >
0 commit comments