@@ -60,10 +60,15 @@ function run() {
6060 }
6161}
6262
63+ // only use with validated input
64+ // https://github.com/nodejs/node/issues/52554
6365function runBat ( ) {
6466 const args = Array . from ( arguments ) ;
6567 console . log ( args . join ( ' ' ) ) ;
6668 const command = args . shift ( ) ;
69+ if ( ! fs . existsSync ( command ) ) {
70+ throw 'Bat not found' ;
71+ }
6772 const ret = spawnSync ( command , args , { stdio : 'inherit' , shell : true } ) ;
6873 if ( ret . status !== 0 ) {
6974 throw ret . error ;
@@ -166,7 +171,7 @@ function installPlugins() {
166171
167172 // validate
168173 plugins . forEach ( function ( plugin ) {
169- if ( ! / ^ \w \S + $ / . test ( plugin ) ) {
174+ if ( ! / ^ \w ( \w | - ) + $ / i . test ( plugin ) ) {
170175 throw `Invalid plugin: ${ plugin } ` ;
171176 }
172177 } ) ;
@@ -176,14 +181,16 @@ function installPlugins() {
176181 const versionParts = elasticsearchVersion . split ( '.' ) ;
177182 const atOnce = parseInt ( versionParts [ 0 ] ) >= 7 && parseInt ( versionParts [ 1 ] ) >= 6 ;
178183 let pluginCmd = path . join ( esHome , 'bin' , 'elasticsearch-plugin' ) ;
184+ let runCmd = run ;
179185 if ( isWindows ( ) ) {
180- throw 'This action does not support plugins on Windows' ;
186+ pluginCmd += '.bat' ;
187+ runCmd = runBat ;
181188 }
182189 if ( atOnce ) {
183- run ( pluginCmd , 'install' , '--silent' , '--batch' , ...plugins ) ;
190+ runCmd ( pluginCmd , 'install' , '--silent' , '--batch' , ...plugins ) ;
184191 } else {
185192 plugins . forEach ( function ( plugin ) {
186- run ( pluginCmd , 'install' , '--silent' , '--batch' , plugin ) ;
193+ runCmd ( pluginCmd , 'install' , '--silent' , '--batch' , plugin ) ;
187194 } ) ;
188195 }
189196 }
0 commit comments