Skip to content
Merged
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
4 changes: 2 additions & 2 deletions src/utils/queryUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -396,7 +396,7 @@ export function formatScratchpadStacktrace(stacktrace: ScratchpadStacktrace) {
.join("\n");
}

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

export function resultToBase64(result: any): string | undefined {
const bytes =
Expand All @@ -405,7 +405,7 @@ export function resultToBase64(result: any): string | undefined {
result;
if (Array.isArray(bytes) && bytes.length > 66) {
for (let i = 0; i < PNG.length; i++) {
if (bytes[i] !== PNG[i] && bytes[i] !== parseInt(PNG[i], 16)) {
if (parseInt(`${bytes[i]}`) !== PNG[i]) {
return undefined;
}
}
Expand Down
18 changes: 12 additions & 6 deletions test/suite/utils.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1996,36 +1996,35 @@ describe("Utils", () => {
const result = queryUtils.resultToBase64(png);
assert.strictEqual(result, undefined);
});
it("should return undefined for undefined for bad signature", () => {
it("should return undefined for bad signature", () => {
const result = queryUtils.resultToBase64([
...png.map((v) => parseInt(v, 16) + 1),
,
...img,
]);
assert.strictEqual(result, undefined);
});
it("should return base64 for minimum img str", () => {
const result = queryUtils.resultToBase64([...png, ...img]);
assert.ok(result.startsWith("data:image/png;base64"));
assert.ok(result);
});
it("should return base64 for minimum img num", () => {
const result = queryUtils.resultToBase64([
...png.map((v) => parseInt(v, 16)),
...img.map((v) => parseInt(v, 16)),
]);
assert.ok(result.startsWith("data:image/png;base64"));
assert.ok(result);
});
it("should return base64 for minimum img str for structuredText", () => {
const result = queryUtils.resultToBase64({
columns: { values: [...png, ...img] },
});
assert.ok(result.startsWith("data:image/png;base64"));
assert.ok(result);
});
it("should return base64 for minimum img str for structuredText v2", () => {
const result = queryUtils.resultToBase64({
columns: [{ values: [...png, ...img] }],
});
assert.ok(result.startsWith("data:image/png;base64"));
assert.ok(result);
});
it("should return undefined for bogus structuredText", () => {
const result = queryUtils.resultToBase64({
Expand All @@ -2039,5 +2038,12 @@ describe("Utils", () => {
});
assert.strictEqual(result, undefined);
});
it("should return base64 from windows q server", () => {
const result = queryUtils.resultToBase64([
...png.map((v) => `${v}\r`),
...img.map((v) => `${v}\r`),
]);
assert.ok(result);
});
});
});