From e9aa71415e339411d8e4cef497a948be209ca641 Mon Sep 17 00:00:00 2001 From: Karstein Phobic Nyvold Kvistad Date: Fri, 12 Jun 2026 13:43:27 +0200 Subject: [PATCH] fix: ASCII-fy add_library.py comment, clean dist/scripts on build, global ASCII test - add_library.py line 49 had UTF-8 box-drawing dashes in a comment with no coding declaration -- latent IronPython 2.7 source-encoding risk. - build now removes dist/scripts before copying, so deleted/renamed templates (compile_project.py.bak, probe_app_error_state.py, set_library_namespace.py) no longer ship in the npm tarball. - script-manager test now asserts EVERY template is ASCII-only instead of per-phase lists. --- package.json | 2 +- src/scripts/add_library.py | 2 +- tests/unit/script-manager.test.ts | 10 ++++++++++ 3 files changed, 12 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index caccec1..e713afc 100644 --- a/package.json +++ b/package.json @@ -12,7 +12,7 @@ "LICENSE" ], "scripts": { - "build": "tsc && node -e \"require('fs').cpSync('src/scripts','dist/scripts',{recursive:true})\"", + "build": "tsc && node -e \"const fs=require('fs');fs.rmSync('dist/scripts',{recursive:true,force:true});fs.cpSync('src/scripts','dist/scripts',{recursive:true})\"", "test": "vitest --run", "test:watch": "vitest", "typecheck": "tsc --noEmit", diff --git a/src/scripts/add_library.py b/src/scripts/add_library.py index 2d02e8f..b744a04 100644 --- a/src/scripts/add_library.py +++ b/src/scripts/add_library.py @@ -46,7 +46,7 @@ FORCE_DUP = "{FORCE_DUP}" == "1" ALLOW_UNRESOLVED = "{ALLOW_UNRESOLVED}" == "1" -# ─── SP-version detection ───────────────────────────────────────────────── +# --- SP-version detection ------------------------------------------------- # # CODESYS reports its build through `sys.version` in the IronPython # embedding (e.g. "CODESYS V3.5 SP22 Patch 1, ScriptEngine 4.2.0.0"). diff --git a/tests/unit/script-manager.test.ts b/tests/unit/script-manager.test.ts index ad75b64..ed11b56 100644 --- a/tests/unit/script-manager.test.ts +++ b/tests/unit/script-manager.test.ts @@ -84,6 +84,16 @@ describe('ScriptManager', () => { expect(result).toBe('path = r"C:\\Program Files\\CODESYS"'); }); + it('EVERY script template is ASCII-only (IronPython 2.7, no coding declaration)', () => { + const fs = require('fs'); + const dir = path.join(__dirname, '..', '..', 'src', 'scripts'); + for (const f of fs.readdirSync(dir) as string[]) { + const body = fs.readFileSync(path.join(dir, f), 'latin1'); + // eslint-disable-next-line no-control-regex + expect(/^[\x00-\x7F]*$/.test(body), `${f} must be ASCII-only`).toBe(true); + } + }); + it('dollar sequences in values are NOT treated as regex replacement patterns', () => { // IEC string literals use $ escapes ($R$N, $$ for a literal $). A plain // string replacement would collapse '$$' to '$' and expand '$&'.