From 3a5a5fc13d69ab164db087e024a850907a409561 Mon Sep 17 00:00:00 2001 From: worksofliam Date: Thu, 5 Dec 2024 10:08:31 -0500 Subject: [PATCH] Fix handling of bad character in extended byte calculation and add corresponding test case Signed-off-by: worksofliam --- src/api/Tools.ts | 3 ++- src/testing/tools.ts | 37 ++++++++++++++++++++++++++++++++++++- 2 files changed, 38 insertions(+), 2 deletions(-) diff --git a/src/api/Tools.ts b/src/api/Tools.ts index 7c760ba1b..875241a4e 100644 --- a/src/api/Tools.ts +++ b/src/api/Tools.ts @@ -123,7 +123,8 @@ export namespace Tools { */ - const extendedBytes = strValue.split(``).map(c => Buffer.byteLength(c) < 3 ? 0 : 1).reduce((a: number, b: number) => a + b, 0); + // 65533 = � (not a double byte character!) + const extendedBytes = strValue.split(``).map(c => (Buffer.byteLength(c) < 3 || c.charCodeAt(0) === 65533) ? 0 : 1).reduce((a: number, b: number) => a + b, 0); slideBytesBy += extendedBytes; if (extendedBytes > 0) { diff --git a/src/testing/tools.ts b/src/testing/tools.ts index 41b94f082..6449f09c8 100644 --- a/src/testing/tools.ts +++ b/src/testing/tools.ts @@ -324,6 +324,41 @@ export const ToolsSuite: TestSuite = { assert.strictEqual(rows[0].CHANGED, 1713453741000); } }, + { + name: `Db2 results with bad character`, test: async () => { + const lines = [ + `DB2>`, + ` ?>`, + ``, + `LIBRARY NAME TYPE ATTRIBUTE TEXT IS_SOURCE SOURCE_LENGTH IASP_NUMBER `, + `---------- ---------- ----- ---------- -------------------------------------------------- ----------- -------------- ------------`, + `LOGOMATE QCLSRC *FILE PF LogoMate� - Sourcen CL 1 112 0`, + `LOGOMATE QCMDSRC *FILE PF LogoMate� - Sourcen CMD 1 112 0`, + `LOGOMATE QMNUSRC *FILE PF LogoMate� - Sourcen MNU 1 112 0`, + `LOGOMATE QPNLSRC *FILE PF LogoMate� - Sourcen PNLGRP 1 112 0`, + `LOGOMATE QRPGLECPY *FILE PF LogoMate� - Sourcen RPGLECPY 1 112 0`, + `LOGOMATE QRPGLEH *FILE PF LogoMate� - Sourcen RPGLEH 1 112 0`, + `LOGOMATE QRPGLESRC *FILE PF LogoMate� - Sourcen RPGLE 1 112 0`, + `LOGOMATE QSQDSRC *FILE PF SQL PROCEDURES 1 160 0`, + `LOGOMATE QSQLSRC *FILE PF LogoMate� - Sourcen SQL 1 112 0`, + `LOGOMATE QSRVSRC *FILE PF LogoMate� - Sourcen SRV 1 112 0`, + ``, + ` 10 RECORD(S) SELECTED.`, + ] + + const rows = Tools.db2Parse(lines.join(`\n`)); + assert.strictEqual(rows.length, 10); + + assert.strictEqual(rows[0].LIBRARY, `LOGOMATE`); + assert.strictEqual(rows[0].NAME, `QCLSRC`); + assert.strictEqual(rows[0].TYPE, `*FILE`); + assert.strictEqual(rows[0].ATTRIBUTE, `PF`); + assert.strictEqual(rows[0].TEXT, `LogoMate� - Sourcen CL`); + assert.strictEqual(rows[0].IS_SOURCE, 1); + assert.strictEqual(rows[0].SOURCE_LENGTH, 112); + assert.strictEqual(rows[0].IASP_NUMBER, 0); + } + }, { name: "Date attr parsing", test: async () => { const date1Epoch = Tools.parseAttrDate(`Fri Apr 5 09:00:10 2024`); @@ -346,6 +381,6 @@ export const ToolsSuite: TestSuite = { assert.strictEqual(date2.getUTCMinutes(), 47); assert.strictEqual(date2.getUTCSeconds(), 2); } - } + }, ] };