Skip to content

Commit 611bfe3

Browse files
authored
Merge pull request #515 from KxSystems/ee-winq
[backport] fixed png detection from a windows q server
2 parents 4e23a57 + 9c5a586 commit 611bfe3

File tree

2 files changed

+14
-8
lines changed

2 files changed

+14
-8
lines changed

src/utils/queryUtils.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -396,7 +396,7 @@ export function formatScratchpadStacktrace(stacktrace: ScratchpadStacktrace) {
396396
.join("\n");
397397
}
398398

399-
const PNG = ["0x89", "0x50", "0x4e", "0x47", "0x0d", "0x0a", "0x1a", "0x0a"];
399+
const PNG = [0x89, 0x50, 0x4e, 0x47, 0x0d, 0x0a, 0x1a, 0x0a];
400400

401401
export function resultToBase64(result: any): string | undefined {
402402
const bytes =
@@ -405,7 +405,7 @@ export function resultToBase64(result: any): string | undefined {
405405
result;
406406
if (Array.isArray(bytes) && bytes.length > 66) {
407407
for (let i = 0; i < PNG.length; i++) {
408-
if (bytes[i] !== PNG[i] && bytes[i] !== parseInt(PNG[i], 16)) {
408+
if (parseInt(`${bytes[i]}`) !== PNG[i]) {
409409
return undefined;
410410
}
411411
}

test/suite/utils.test.ts

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1996,36 +1996,35 @@ describe("Utils", () => {
19961996
const result = queryUtils.resultToBase64(png);
19971997
assert.strictEqual(result, undefined);
19981998
});
1999-
it("should return undefined for undefined for bad signature", () => {
1999+
it("should return undefined for bad signature", () => {
20002000
const result = queryUtils.resultToBase64([
20012001
...png.map((v) => parseInt(v, 16) + 1),
2002-
,
20032002
...img,
20042003
]);
20052004
assert.strictEqual(result, undefined);
20062005
});
20072006
it("should return base64 for minimum img str", () => {
20082007
const result = queryUtils.resultToBase64([...png, ...img]);
2009-
assert.ok(result.startsWith("data:image/png;base64"));
2008+
assert.ok(result);
20102009
});
20112010
it("should return base64 for minimum img num", () => {
20122011
const result = queryUtils.resultToBase64([
20132012
...png.map((v) => parseInt(v, 16)),
20142013
...img.map((v) => parseInt(v, 16)),
20152014
]);
2016-
assert.ok(result.startsWith("data:image/png;base64"));
2015+
assert.ok(result);
20172016
});
20182017
it("should return base64 for minimum img str for structuredText", () => {
20192018
const result = queryUtils.resultToBase64({
20202019
columns: { values: [...png, ...img] },
20212020
});
2022-
assert.ok(result.startsWith("data:image/png;base64"));
2021+
assert.ok(result);
20232022
});
20242023
it("should return base64 for minimum img str for structuredText v2", () => {
20252024
const result = queryUtils.resultToBase64({
20262025
columns: [{ values: [...png, ...img] }],
20272026
});
2028-
assert.ok(result.startsWith("data:image/png;base64"));
2027+
assert.ok(result);
20292028
});
20302029
it("should return undefined for bogus structuredText", () => {
20312030
const result = queryUtils.resultToBase64({
@@ -2039,5 +2038,12 @@ describe("Utils", () => {
20392038
});
20402039
assert.strictEqual(result, undefined);
20412040
});
2041+
it("should return base64 from windows q server", () => {
2042+
const result = queryUtils.resultToBase64([
2043+
...png.map((v) => `${v}\r`),
2044+
...img.map((v) => `${v}\r`),
2045+
]);
2046+
assert.ok(result);
2047+
});
20422048
});
20432049
});

0 commit comments

Comments
 (0)