objection.js
objection.js copied to clipboard
knexSnakeCaseMappers fails to check for nullish identifiers
In some rare situation, knex may throw a null/undefined as the first argument of wrapIdentifier. Objection's snake case mappers does not check for this and just crashes. Reproduction :
import {knexSnakeCaseMappers} from "objection";
import Knex from "knex";
const db = Knex.knex({client: "sqlite3", connection: {filename: "test.db"}, ...knexSnakeCaseMappers()});
console.log(db.schema.createTable("test", t => {
t.string("uuid").notNullable().primary();
}).toSQL());
Error :
/home/sloonz/workspace/node_modules/objection/lib/utils/identifierMapping.js:138
const idx = str.lastIndexOf(separator);
TypeError: Cannot read properties of undefined (reading 'lastIndexOf')
Not 100% sure whether if it's objection fault for not checking or knex fault for giving nullish values, but I’ll start there ;)