Skip to content

Commit cd182dc

Browse files
committed
Rebuild dist with improved code and updated logic
1 parent 47c3a97 commit cd182dc

1 file changed

Lines changed: 55 additions & 77 deletions

File tree

dist/index.js

Lines changed: 55 additions & 77 deletions
Original file line numberDiff line numberDiff line change
@@ -6837,6 +6837,8 @@ exports["default"] = _default;
68376837

68386838
Object.defineProperty(exports, "__esModule", ({ value: true }));
68396839
exports.DEFAULT_OUTPUT_KEY = void 0;
6840+
// Output name used when the map value is a primitive and no output_key_name is given.
6841+
// Exposed to workflows as ${{ steps.<id>.outputs.value }}.
68406842
exports.DEFAULT_OUTPUT_KEY = 'value';
68416843

68426844

@@ -6890,11 +6892,11 @@ const main = (controls) => {
68906892
const map = controls.getInput('map');
68916893
const key = controls.getInput('key');
68926894
const defaultKey = controls.getInput('default_key');
6893-
const outputName = controls.getInput('output_key_name');
6895+
const outputKeyName = controls.getInput('output_key_name');
68946896
try {
6895-
const result = (0, processing_1.processing)(map, key, defaultKey, outputName);
6896-
controls.info(`result: ${JSON.stringify(result)}`);
6897-
Object.entries(result).forEach(([key, value]) => controls.setOutput(key, value));
6897+
const result = (0, processing_1.processing)(map, key, defaultKey, outputKeyName);
6898+
controls.info(`output keys: ${Object.keys(result).join(', ')}`);
6899+
Object.entries(result).forEach(([outputKey, value]) => controls.setOutput(outputKey, value));
68986900
}
68996901
catch (err) {
69006902
const message = err instanceof Error ? err.message : 'Error';
@@ -6907,113 +6909,89 @@ exports.main = main;
69076909
/***/ }),
69086910

69096911
/***/ 1609:
6910-
/***/ (function(__unused_webpack_module, exports, __nccwpck_require__) {
6912+
/***/ ((__unused_webpack_module, exports, __nccwpck_require__) => {
69116913

69126914
"use strict";
69136915

6914-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
6915-
if (k2 === undefined) k2 = k;
6916-
var desc = Object.getOwnPropertyDescriptor(m, k);
6917-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6918-
desc = { enumerable: true, get: function() { return m[k]; } };
6919-
}
6920-
Object.defineProperty(o, k2, desc);
6921-
}) : (function(o, m, k, k2) {
6922-
if (k2 === undefined) k2 = k;
6923-
o[k2] = m[k];
6924-
}));
6925-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
6926-
Object.defineProperty(o, "default", { enumerable: true, value: v });
6927-
}) : function(o, v) {
6928-
o["default"] = v;
6929-
});
6930-
var __importStar = (this && this.__importStar) || function (mod) {
6931-
if (mod && mod.__esModule) return mod;
6932-
var result = {};
6933-
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
6934-
__setModuleDefault(result, mod);
6935-
return result;
6936-
};
69376916
Object.defineProperty(exports, "__esModule", ({ value: true }));
69386917
exports.parse = void 0;
69396918
const js_yaml_1 = __nccwpck_require__(1917);
6940-
const core = __importStar(__nccwpck_require__(2186));
6941-
const isString = (value) => typeof value === 'string';
6942-
const isNotEmptyString = (value) => isString(value) && !!value;
6943-
const isJSON = (value) => isNotEmptyString(value) && /^\{((.|\n)*)\}$/.test(value);
6944-
const isYaml = (value) => isNotEmptyString(value) && !isJSON(value) && /^[a-zA-Z0-9-_\s\(\)]+(\s+)?:/.test(value);
6919+
const MAX_INPUT_LENGTH = 64 * 1024;
6920+
const tryJSON = (str) => {
6921+
try {
6922+
return JSON.parse(str);
6923+
}
6924+
catch {
6925+
return undefined;
6926+
}
6927+
};
6928+
const tryYAML = (str) => {
6929+
try {
6930+
return (0, js_yaml_1.load)(str);
6931+
}
6932+
catch {
6933+
return undefined;
6934+
}
6935+
};
6936+
const isPlainObject = (value) => value !== null && typeof value === 'object' && !Array.isArray(value);
69456937
const parse = (value) => {
6938+
if (typeof value !== 'string')
6939+
throw new Error(`Empty map value`);
69466940
const str = value.trim();
6947-
core.debug(`Input map: ${str}`);
6948-
if (!isNotEmptyString(str))
6941+
if (!str)
69496942
throw new Error(`Empty map value`);
6950-
if (isJSON(str))
6951-
return JSON.parse(str);
6952-
if (isYaml(str))
6953-
return (0, js_yaml_1.load)(str);
6954-
throw new Error(`Incorect map format. Acceptable formats are json or yaml`);
6943+
if (str.length > MAX_INPUT_LENGTH)
6944+
throw new Error(`Map value exceeds ${MAX_INPUT_LENGTH} bytes`);
6945+
const parsed = tryJSON(str) ?? tryYAML(str);
6946+
if (parsed === undefined)
6947+
throw new Error(`Incorrect map format. Acceptable formats are json or yaml`);
6948+
if (!isPlainObject(parsed))
6949+
throw new Error(`Map must be a key-value object`);
6950+
return parsed;
69556951
};
69566952
exports.parse = parse;
69576953

69586954

69596955
/***/ }),
69606956

69616957
/***/ 456:
6962-
/***/ (function(__unused_webpack_module, exports, __nccwpck_require__) {
6958+
/***/ ((__unused_webpack_module, exports, __nccwpck_require__) => {
69636959

69646960
"use strict";
69656961

6966-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
6967-
if (k2 === undefined) k2 = k;
6968-
var desc = Object.getOwnPropertyDescriptor(m, k);
6969-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6970-
desc = { enumerable: true, get: function() { return m[k]; } };
6971-
}
6972-
Object.defineProperty(o, k2, desc);
6973-
}) : (function(o, m, k, k2) {
6974-
if (k2 === undefined) k2 = k;
6975-
o[k2] = m[k];
6976-
}));
6977-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
6978-
Object.defineProperty(o, "default", { enumerable: true, value: v });
6979-
}) : function(o, v) {
6980-
o["default"] = v;
6981-
});
6982-
var __importStar = (this && this.__importStar) || function (mod) {
6983-
if (mod && mod.__esModule) return mod;
6984-
var result = {};
6985-
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
6986-
__setModuleDefault(result, mod);
6987-
return result;
6988-
};
69896962
Object.defineProperty(exports, "__esModule", ({ value: true }));
69906963
exports.processing = void 0;
6991-
const core = __importStar(__nccwpck_require__(2186));
69926964
const parsers_1 = __nccwpck_require__(1609);
69936965
const constants_1 = __nccwpck_require__(9042);
6994-
const normalizeOutput = (output, keyName) => {
6995-
if (output && typeof output === 'object') {
6996-
if (keyName)
6997-
throw new Error(`The result is an object "${JSON.stringify(output)}". The default_key (${keyName}) parameter does not apply to objects`);
6966+
const FORBIDDEN_OUTPUT_KEYS = new Set(['__proto__', 'prototype', 'constructor']);
6967+
const isPlainObject = (value) => value !== null && typeof value === 'object' && !Array.isArray(value);
6968+
const normalizeOutput = (output, outputKeyName) => {
6969+
if (isPlainObject(output)) {
6970+
if (outputKeyName)
6971+
throw new Error(`Map value is an object - output_key_name (${outputKeyName}) is not applicable`);
69986972
if (!Object.keys(output).length)
69996973
throw new Error(`Empty output object`);
70006974
return output;
70016975
}
6976+
if (Array.isArray(output))
6977+
throw new Error(`Array result is not supported`);
70026978
if (output == null)
70036979
throw new Error(`Missing output`);
7004-
return keyName ? { [keyName]: output } : { [constants_1.DEFAULT_OUTPUT_KEY]: output };
6980+
const target = outputKeyName || constants_1.DEFAULT_OUTPUT_KEY;
6981+
if (FORBIDDEN_OUTPUT_KEYS.has(target))
6982+
throw new Error(`output_key_name "${target}" is not allowed`);
6983+
return { [target]: output };
70056984
};
7006-
const processing = (map, key, defaultKey, keyName) => {
6985+
const processing = (map, key, defaultKey, outputKeyName) => {
70076986
if (!key && !defaultKey)
70086987
throw new Error('One of the key or default_key parameters is mandatory');
70096988
const obj = (0, parsers_1.parse)(map);
7010-
core.debug(`input: ${JSON.stringify(obj)}`);
7011-
if (key && key in obj)
7012-
return normalizeOutput(obj[key], keyName);
6989+
if (key && Object.hasOwn(obj, key))
6990+
return normalizeOutput(obj[key], outputKeyName);
70136991
if (!defaultKey)
7014-
throw new Error(`default_key is required if there is no master key or if the result of a condition is missing`);
7015-
if (defaultKey in obj)
7016-
return normalizeOutput(obj[defaultKey], keyName);
6992+
throw new Error(`default_key is required when key is not found in the map`);
6993+
if (Object.hasOwn(obj, defaultKey))
6994+
return normalizeOutput(obj[defaultKey], outputKeyName);
70176995
throw new Error(`default_key (${defaultKey}) must match one of the keys in the map`);
70186996
};
70196997
exports.processing = processing;

0 commit comments

Comments
 (0)