@@ -10282,11 +10282,12 @@ const execShellCommand = (cmd) => {
1028210282
1028310283/**
1028410284 * @param {string } key
10285- * @return {string }
10285+ * @param {regex } re regex to use for validation
10286+ * @return {string }, {undefined} or throws an error if input doesn't match regex
1028610287 */
10287- const getValidatedInput = ( key ) => {
10288+ const getValidatedInput = ( key , re ) => {
1028810289 const value = core . getInput ( key ) ;
10289- if ( / ^ [ - . + A - Z a - z 0 - 9 ] * $ / . test ( value ) ) {
10290+ if ( value !== undefined && ! re . test ( value ) ) {
1029010291 throw new Error ( `Invalid value for '${ key } ': '${ value } '` ) ;
1029110292 }
1029210293 return value ;
@@ -10406,11 +10407,21 @@ async function run() {
1040610407 await execShellCommand ( `echo 'set +e' >/tmp/tmate.bashrc` ) ;
1040710408 let setDefaultCommand = `set-option -g default-command "bash --rcfile /tmp/tmate.bashrc" \\;` ;
1040810409
10409- if ( core . getInput ( "tmate-server-host" ) !== "" ) {
10410- setDefaultCommand = `${ setDefaultCommand } set-option -g tmate-server-host "${ getValidatedInput ( "tmate-server-host" ) } " \\;` ;
10411- setDefaultCommand = `${ setDefaultCommand } set-option -g tmate-server-port "${ getValidatedInput ( "tmate-server-port" ) } " \\;` ;
10412- setDefaultCommand = `${ setDefaultCommand } set-option -g tmate-server-rsa-fingerprint "${ getValidatedInput ( "tmate-server-rsa-fingerprint" ) } " \\;` ;
10413- setDefaultCommand = `${ setDefaultCommand } set-option -g tmate-server-ed25519-fingerprint "${ getValidatedInput ( "tmate-server-ed25519-fingerprint" ) } " \\;` ;
10410+ // The regexes used here for validation are lenient, i.e. may accept
10411+ // values that are not, strictly speaking, valid, but should be good
10412+ // enough for detecting obvious errors, which is all we want here.
10413+ const options = {
10414+ "tmate-server-host" : / ^ [ a - z \d \- ] + ( \. [ a - z \d \- ] + ) * $ / i,
10415+ "tmate-server-port" : / ^ \d { 1 , 5 } $ / ,
10416+ "tmate-server-rsa-fingerprint" : / ./ ,
10417+ "tmate-server-ed25519-fingerprint" : / ./ ,
10418+ }
10419+
10420+ for ( const opt in options ) {
10421+ const value = getValidatedInput ( opt , options [ opt ] ) ;
10422+ if ( value !== undefined ) {
10423+ setDefaultCommand = `${ setDefaultCommand } set-option -g ${ opt } "${ value } " \\;` ;
10424+ }
1041410425 }
1041510426
1041610427 core . debug ( "Creating new session" )
0 commit comments