Convert all values to string where possible, even if not derived from a table (#18210)
## Addresses #17946 results from querying chrome extension on macOS Chrome browser:  - [x] Changes file added for user-visible changes in `changes/` - [x] Updated tests - [x] Manual QA for all new/changed functionality - [ ] TODO - Manual QA on actual Chromebook --------- Co-authored-by: Jacob Shandling <jacob@fleetdm.com>
This commit is contained in:
co-authored by
Jacob Shandling
parent
8159c2b44f
commit
02563ffef9
@@ -0,0 +1,2 @@
|
||||
- Fix a bug where values not derived from "actual" fleetd-chrome tables were not being displayed
|
||||
correctly (e.g., `SELECT 1` gets its value from the query itself, not a table)
|
||||
@@ -3,5 +3,5 @@ import VirtualDatabase from "./db";
|
||||
test("Simple query", async () => {
|
||||
const db = await VirtualDatabase.init();
|
||||
const res = await db.query("select 1");
|
||||
expect(res).toEqual({"data": [{ "1": 1 }], "warnings": null});
|
||||
expect(res).toEqual({ data: [{ "1": "1" }], warnings: null });
|
||||
});
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
import SQLiteAsyncESMFactory from "wa-sqlite/dist/wa-sqlite-async.mjs";
|
||||
import * as SQLite from "wa-sqlite";
|
||||
|
||||
// Alphabetical order
|
||||
import Table from "./tables/Table";
|
||||
import TableChromeExtensions from "./tables/chrome_extensions";
|
||||
import TableDiskInfo from "./tables/disk_info";
|
||||
@@ -34,7 +33,6 @@ export default class VirtualDatabase {
|
||||
this.sqlite3 = sqlite3;
|
||||
this.db = db;
|
||||
|
||||
// Alphabetical order
|
||||
VirtualDatabase.register(
|
||||
sqlite3,
|
||||
db,
|
||||
@@ -81,7 +79,23 @@ export default class VirtualDatabase {
|
||||
await this.sqlite3.exec(this.db, sql, (row, columns) => {
|
||||
// map each row to object
|
||||
rows.push(
|
||||
Object.fromEntries(columns.map((_, i) => [columns[i], row[i]]))
|
||||
Object.fromEntries(
|
||||
columns.map((_, i) => {
|
||||
let [colName, val] = [columns[i], row[i]];
|
||||
if (typeof val !== "string") {
|
||||
if (val.toString) {
|
||||
val = val.toString();
|
||||
} else {
|
||||
this.warnings.push({
|
||||
column: colName,
|
||||
error_message: `Value is not a string and doesn't have a toString method: ${val}`,
|
||||
});
|
||||
val = null;
|
||||
}
|
||||
}
|
||||
return [colName, val];
|
||||
})
|
||||
)
|
||||
);
|
||||
});
|
||||
return { data: rows, warnings: this.warnings };
|
||||
|
||||
Reference in New Issue
Block a user