From 9fe64a7e062c649766fd4966d952109ea91ce6ca Mon Sep 17 00:00:00 2001 From: hawkeyexl Date: Tue, 3 Jun 2025 11:04:55 -0700 Subject: [PATCH 1/3] Update regex for httpRequestFormat to better support Windows line endings --- src/config.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/config.js b/src/config.js index b2b85bb..a4d59f0 100644 --- a/src/config.js +++ b/src/config.js @@ -110,7 +110,7 @@ let defaultFileTypes = { { name: "httpRequestFormat", regex: [ - "```(?:http)?\\n([A-Z]+)\\s+([^\\s]+)(?:\\s+HTTP\\/[\\d.]+)?\\s((?:[^\\s]+\\s?)*)(?:\\s([\\s\\S]*)\\s)?```", + "```(?:http)?\\r?\\n([A-Z]+)\\s+([^\\s]+)(?:\\s+HTTP\\/[\\d.]+)?\\r?\\n((?:[^\\s]+:\\s+[^\\s]+\\r?\\n)*)?(?:\\s+([\\s\\S]*)\\s+)?```", ], actions: [ { From 05b6f7afab1e2eb599e63a31bde278c19e56962f Mon Sep 17 00:00:00 2001 From: hawkeyexl Date: Tue, 3 Jun 2025 11:05:11 -0700 Subject: [PATCH 2/3] Enhance variable substitution in parseContent function - Check for existence of all $n variables before substitution - Return null if any variable is missing - Delete keys from stringOrObject if their corresponding $n variables are missing - Clean up formatting for better readability --- src/utils.js | 54 ++++++++++++++++++++++++++++++++++++++++++---------- 1 file changed, 44 insertions(+), 10 deletions(-) diff --git a/src/utils.js b/src/utils.js index 85994ec..2adaf3f 100644 --- a/src/utils.js +++ b/src/utils.js @@ -295,10 +295,26 @@ async function parseContent({ config, content, filePath, fileType }) { if (typeof stringOrObject === "string") { // Replace $n with values[n] - stringOrObject = stringOrObject.replace(/\$[0-9]+/g, (variable) => { - const index = variable.substring(1); - return values[index]; - }); + // Find all $n variables in the string + const matches = stringOrObject.match(/\$[0-9]+/g); + if (matches) { + // Check if all variables exist in values + const allExist = matches.every((variable) => { + const index = variable.substring(1); + return ( + values.hasOwnProperty(index) && typeof values[index] !== "undefined" + ); + }); + if (!allExist) { + return null; + } else { + // Perform substitution + stringOrObject = stringOrObject.replace(/\$[0-9]+/g, (variable) => { + const index = variable.substring(1); + return values[index]; + }); + } + } } Object.keys(stringOrObject).forEach((key) => { @@ -310,13 +326,29 @@ async function parseContent({ config, content, filePath, fileType }) { ); } else if (typeof stringOrObject[key] === "string") { // Replace $n with values[n] - stringOrObject[key] = stringOrObject[key].replace( - /\$[0-9]+/g, - (variable) => { + const matches = stringOrObject[key].match(/\$[0-9]+/g); + if (matches) { + // Check if all variables exist in values + const allExist = matches.every((variable) => { const index = variable.substring(1); - return values[index]; + return ( + values.hasOwnProperty(index) && + typeof values[index] !== "undefined" + ); + }); + if (!allExist) { + delete stringOrObject[key]; + } else { + // Perform substitution + stringOrObject[key] = stringOrObject[key].replace( + /\$[0-9]+/g, + (variable) => { + const index = variable.substring(1); + return values[index]; + } + ); } - ); + } } return key; }); @@ -660,7 +692,9 @@ async function parseTests({ config, files }) { spec.tests.push(...tests); // Remove tests with no steps - spec.tests = spec.tests.filter((test) => test.steps && test.steps.length > 0); + spec.tests = spec.tests.filter( + (test) => test.steps && test.steps.length > 0 + ); // Push spec to specs, if it is valid const validation = validate({ From 95e867aa93268479e440a3c3c18c4b1b19e3d9be Mon Sep 17 00:00:00 2001 From: hawkeyexl Date: Tue, 3 Jun 2025 11:09:45 -0700 Subject: [PATCH 3/3] Replace deprecated hasOwnProperty with Object.hasOwn in parseContent function --- src/utils.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/utils.js b/src/utils.js index 2adaf3f..c98f522 100644 --- a/src/utils.js +++ b/src/utils.js @@ -302,7 +302,7 @@ async function parseContent({ config, content, filePath, fileType }) { const allExist = matches.every((variable) => { const index = variable.substring(1); return ( - values.hasOwnProperty(index) && typeof values[index] !== "undefined" + Object.hasOwn(values, index) && typeof values[index] !== "undefined" ); }); if (!allExist) { @@ -332,7 +332,7 @@ async function parseContent({ config, content, filePath, fileType }) { const allExist = matches.every((variable) => { const index = variable.substring(1); return ( - values.hasOwnProperty(index) && + Object.hasOwn(values, index) && typeof values[index] !== "undefined" ); });