From 150830c5af06aa6a2f14207b7783d8f1e77841c6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ari=20Ker=C3=A4nen?= Date: Mon, 25 May 2026 22:41:01 +0300 Subject: [PATCH] Fix parse crash, validCharsCheck stringification, CLI option parsing, and process.exit flushing --- sdflint/sdflint.js | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/sdflint/sdflint.js b/sdflint/sdflint.js index e91c1c4..4546e5c 100644 --- a/sdflint/sdflint.js +++ b/sdflint/sdflint.js @@ -35,8 +35,14 @@ if (require.main === module) { /* run as stand-alone? */ let schemaFile; process.argv.slice(3).forEach((option) => { - let name = option.substring(0, option.indexOf("=")); - let value = option.substring(option.indexOf("=") + 1); + let eqIndex = option.indexOf("="); + if (eqIndex === -1) { + console.error("Invalid option (missing '='): " + option); + process.exitCode = 1; + return; + } + let name = option.substring(0, eqIndex); + let value = option.substring(eqIndex + 1); options[name] = value; }); @@ -63,7 +69,7 @@ if (require.main === module) { /* run as stand-alone? */ sdfLint(sdfFile, schema, res, options); console.dir(res, { depth: null }); - process.exit(res.errorCount); + process.exitCode = res.errorCount; } else { console.log(` @@ -90,8 +96,7 @@ function fileNameCheck(fileName, res) { } -function validCharsCheck(sdfFile, res) { - let sdfStr = JSON.stringify(sdfFile); +function validCharsCheck(sdfStr, res) { if (!sdfStr) { res.errorCount++; res.errors.file = "Invalid SDF file"; @@ -140,6 +145,7 @@ function sdfLint(sdfFile, schema, res, options) { } catch (err) { res.errorCount++; res.errors.parse = err.message; + return res; } validCharsCheck(sdfFile, res); }