Skip to content
Merged
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
16 changes: 14 additions & 2 deletions src/GoogleSheets.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import { getUploadedData, getVehicleIdFromLogs, getFirstLogDate } from "./localStorage";
import { log } from "./Utils";
import { GOOGLE_CLIENT_ID } from "./constants";
import _ from "lodash";

const SHEETS_API_BASE = "https://sheets.googleapis.com/v4/spreadsheets";
const CLIENT_ID = GOOGLE_CLIENT_ID;
Expand Down Expand Up @@ -278,6 +277,19 @@
throw new Error("Invalid spreadsheet URL or ID");
}

function setDeep(obj, path, value) {
const segments = typeof path === "string" ? path.split(".") : path;
let current = obj;
for (let i = 0; i < segments.length - 1; i++) {
const key = segments[i];
if (current[key] === undefined || current[key] === null || typeof current[key] !== "object") {
current[key] = {};
}
current = current[key];
}
current[segments[segments.length - 1]] = value;

Check warning

Code scanning / CodeQL

Prototype-polluting function Medium

The property chain
here
is recursively assigned to
current
without guarding against prototype pollution.
}

export async function importFromGoogleSheet(spreadsheetInput, token) {
const spreadsheetId = extractSpreadsheetId(spreadsheetInput);
log(`Importing from spreadsheet: ${spreadsheetId}`);
Expand Down Expand Up @@ -306,7 +318,7 @@
for (let j = 0; j < originalHeaders.length; j++) {
const value = fromCellValue(j < row.length ? row[j] : undefined);
if (value !== undefined) {
_.set(obj, originalHeaders[j], value);
setDeep(obj, originalHeaders[j], value);
}
}
allLogs.push(obj);
Expand Down
Loading