objection.js icon indicating copy to clipboard operation
objection.js copied to clipboard

knexSnakeCaseMappers fails to check for nullish identifiers

Open sloonz opened this issue 3 years ago • 0 comments

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 ;)

sloonz avatar Nov 07 '22 09:11 sloonz