mirror of
https://github.com/shivammathur/setup-php.git
synced 2024-11-26 13:23:05 +07:00
Fix to make utils.readEnv more resilient to user input
This commit is contained in:
parent
7bd9f10bef
commit
4bb4f1812c
@ -19,7 +19,11 @@ async function cleanup(path: string): Promise<void> {
|
|||||||
describe('Utils tests', () => {
|
describe('Utils tests', () => {
|
||||||
it('checking readEnv', async () => {
|
it('checking readEnv', async () => {
|
||||||
process.env['test'] = 'setup-php';
|
process.env['test'] = 'setup-php';
|
||||||
|
process.env['test-hyphen'] = 'setup-php';
|
||||||
expect(await utils.readEnv('test')).toBe('setup-php');
|
expect(await utils.readEnv('test')).toBe('setup-php');
|
||||||
|
expect(await utils.readEnv('TEST')).toBe('setup-php');
|
||||||
|
expect(await utils.readEnv('test_hyphen')).toBe('setup-php');
|
||||||
|
expect(await utils.readEnv('TEST_HYPHEN')).toBe('setup-php');
|
||||||
expect(await utils.readEnv('undefined')).toBe('');
|
expect(await utils.readEnv('undefined')).toBe('');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
15
dist/index.js
vendored
15
dist/index.js
vendored
@ -877,13 +877,14 @@ const path = __importStar(__nccwpck_require__(622));
|
|||||||
const url = __importStar(__nccwpck_require__(835));
|
const url = __importStar(__nccwpck_require__(835));
|
||||||
const core = __importStar(__nccwpck_require__(186));
|
const core = __importStar(__nccwpck_require__(186));
|
||||||
async function readEnv(property) {
|
async function readEnv(property) {
|
||||||
const value = process.env[property];
|
const property_lc = property.toLowerCase();
|
||||||
switch (value) {
|
const property_uc = property.toUpperCase();
|
||||||
case undefined:
|
return (process.env[property] ||
|
||||||
return '';
|
process.env[property_lc] ||
|
||||||
default:
|
process.env[property_uc] ||
|
||||||
return value;
|
process.env[property_lc.replace('_', '-')] ||
|
||||||
}
|
process.env[property_uc.replace('_', '-')] ||
|
||||||
|
'');
|
||||||
}
|
}
|
||||||
exports.readEnv = readEnv;
|
exports.readEnv = readEnv;
|
||||||
async function getInput(name, mandatory) {
|
async function getInput(name, mandatory) {
|
||||||
|
17
src/utils.ts
17
src/utils.ts
@ -11,13 +11,16 @@ import * as core from '@actions/core';
|
|||||||
* @param property
|
* @param property
|
||||||
*/
|
*/
|
||||||
export async function readEnv(property: string): Promise<string> {
|
export async function readEnv(property: string): Promise<string> {
|
||||||
const value = process.env[property];
|
const property_lc: string = property.toLowerCase();
|
||||||
switch (value) {
|
const property_uc: string = property.toUpperCase();
|
||||||
case undefined:
|
return (
|
||||||
return '';
|
process.env[property] ||
|
||||||
default:
|
process.env[property_lc] ||
|
||||||
return value;
|
process.env[property_uc] ||
|
||||||
}
|
process.env[property_lc.replace('_', '-')] ||
|
||||||
|
process.env[property_uc.replace('_', '-')] ||
|
||||||
|
''
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Loading…
Reference in New Issue
Block a user