jeremydaly / data-api-client

A "DocumentClient" for the Amazon Aurora Serverless Data API
MIT License
446 stars 63 forks source link

The p.value check in noramlizeParams is broken #73

Closed stevehogdahl closed 3 years ago

stevehogdahl commented 3 years ago

The following use case is broken because the p.value check in noramlizeParams is broken.

dataApi.query( 'SELECT name FROM asset WHERE name = :name AND tenant_id = :tenantId, 
{
    name:     body.name,
    tenantId: parseInt( validate.pathParameters.tenantId )
} );

The p.value undefined should be either p.value !== undefined or typeof p.value !== 'undefined'.

ffxsam commented 3 years ago

Can you give an example of how this is broken? Some sort of error, or show the expected & actual results?

stevehogdahl commented 3 years ago

(Object.keys(p).length === 2 && p.name && p.value !== 'undefined') returns true for the following query and parameters. As you can see there is no value parameter, but it still returns true p.value !== 'undefined'. The error is that :name doesn't get parameterized.

dataApi.query( 'SELECT name FROM asset WHERE name = :name AND tenant_id = :tenantId, 
{
    name:     body.name,
    tenantId: parseInt( validate.pathParameters.tenantId )
} );
ffxsam commented 3 years ago

Fixed, and confirmed working. Thanks! @jeremydaly will have to publish to npm, I don't have permissions to do so.

stevehogdahl commented 3 years ago

Thanks for the responses/fix!