nodejs Validate.dbValues is not blocking bad values (To staff: Root cause identified)

nodejs Validate.dbValues is not blocking bad values (To staff: Root cause identified)

k2digitalk2digital Posts: 1Questions: 1Answers: 0
edited September 2020 in Free community support

As title suggests, Validate.dbValues does not work, and it always passes not matter what I input (using Fiddler). For example, with this code, the validation will always passes and DB error (FK constraint failed) will be returned

new Field('project_user.userId')
          .options(new Options().table('user').value('id').label(['name']))
          .validator(Validate.dbValues(null, 'id', 'user')),

The root case is easy to identify. In datatables.net-editor-server/src/validators.ts dbValues function, the last few lines reads:

let res = await db( table )
    .select( column )
    .where( { [column]: val } );

return ! res ?
    opts.message :
    true;

The problem is, in knex, select always returns an array, so even if the validation suppose to fail (a non-existent val), it will still pass because res is then [] and is truthy , and as a result, the ternary returns true and erroneously passes validation.

Answers

  • allanallan Posts: 61,446Questions: 1Answers: 10,054 Site admin

    Thanks! Committed in here and will be available in the Editor package we should be releasing tomorrow.

    Allan

This discussion has been closed.