Skip to content

Commit

Permalink
Merge pull request #109 from mxschmitt/fix-validation
Browse files Browse the repository at this point in the history
fix: validation of input parameters
  • Loading branch information
dscho authored Feb 13, 2022
2 parents bf9f18e + cb96de3 commit 8b4e4ac
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 10 deletions.
12 changes: 7 additions & 5 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -10282,8 +10282,8 @@ const execShellCommand = (cmd) => {

/**
* @param {string} key
* @param {regex} re regex to use for validation
* @return {string}, {undefined} or throws an error if input doesn't match regex
* @param {RegExp} re regex to use for validation
* @return {string} {undefined} or throws an error if input doesn't match regex
*/
const getValidatedInput = (key, re) => {
const value = core.getInput(key);
Expand Down Expand Up @@ -10417,10 +10417,12 @@ async function run() {
"tmate-server-ed25519-fingerprint": /./,
}

for (const opt in options) {
const value = getValidatedInput(opt, options[opt]);
for (const [key, option] of Object.entries(options)) {
if (core.getInput(key) === '')
continue;
const value = getValidatedInput(key, option);
if (value !== undefined) {
setDefaultCommand = `${setDefaultCommand} set-option -g ${opt} "${value}" \\;`;
setDefaultCommand = `${setDefaultCommand} set-option -g ${key} "${value}" \\;`;
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ export const execShellCommand = (cmd) => {

/**
* @param {string} key
* @param {regex} re regex to use for validation
* @return {string}, {undefined} or throws an error if input doesn't match regex
* @param {RegExp} re regex to use for validation
* @return {string} {undefined} or throws an error if input doesn't match regex
*/
export const getValidatedInput = (key, re) => {
const value = core.getInput(key);
Expand Down
8 changes: 5 additions & 3 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -107,10 +107,12 @@ export async function run() {
"tmate-server-ed25519-fingerprint": /./,
}

for (const opt in options) {
const value = getValidatedInput(opt, options[opt]);
for (const [key, option] of Object.entries(options)) {
if (core.getInput(key) === '')
continue;
const value = getValidatedInput(key, option);
if (value !== undefined) {
setDefaultCommand = `${setDefaultCommand} set-option -g ${opt} "${value}" \\;`;
setDefaultCommand = `${setDefaultCommand} set-option -g ${key} "${value}" \\;`;
}
}

Expand Down

0 comments on commit 8b4e4ac

Please sign in to comment.