Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix bad character handling in extended byte calculation and add tests #2403

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/api/Tools.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
37 changes: 36 additions & 1 deletion src/testing/tools.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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`);
Expand All @@ -346,6 +381,6 @@ export const ToolsSuite: TestSuite = {
assert.strictEqual(date2.getUTCMinutes(), 47);
assert.strictEqual(date2.getUTCSeconds(), 2);
}
}
},
]
};
Loading