Skip to content

Commit

Permalink
fix(crud-request): prevent query bigint casted to number in order to …
Browse files Browse the repository at this point in the history
…prevent dataloss
  • Loading branch information
jdolieslager committed Oct 6, 2019
1 parent 0cdd3dc commit 64cc2cb
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
6 changes: 6 additions & 0 deletions packages/crud-request/src/request-query.parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,12 @@ export class RequestQueryParser implements ParsedRequestParams {
if (!isDate(parsed) && isObject(parsed)) {
// throw new Error('Don\'t support object now');
return val;
} else if (
typeof parsed === 'number' &&
parsed.toLocaleString('fullwide', { useGrouping: false }) !== val
) {
// JS cannot handle big numbers. Leave it as a string to prevent data loss
return val;
}

return parsed;
Expand Down
8 changes: 8 additions & 0 deletions packages/crud-request/test/request-query.parser.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,14 @@ describe('#request-query', () => {
const test = qp.parseQuery(query);
expect(test.filter[0]).toMatchObject(expected[0]);
});
it('should set string, 11', () => {
const query = { filter: ['foo||eq||4202140192612927005304000000236630'] };
const expected: QueryFilter[] = [
{ field: 'foo', operator: 'eq', value: '4202140192612927005304000000236630' },
];
const test = qp.parseQuery(query);
expect(test.filter[0]).toMatchObject(expected[0]);
});
});

describe('#parse or', () => {
Expand Down

0 comments on commit 64cc2cb

Please sign in to comment.