Skip to content

Commit a688fbe

Browse files
authored
Merge pull request #448 from storyofams/fix/string-body-validation
[fix] string body validation
2 parents 7a651de + be91543 commit a688fbe

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

lib/internals/validateObject.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ export async function validateObject(
1919
return value;
2020
}
2121

22-
if (value == null || (typeof value === 'string' && !value.trim().length)) {
22+
if (value == null || typeof value !== 'object') {
2323
value = {};
2424
}
2525

lib/pipes/validators/validation.pipe.spec.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,4 +65,19 @@ describe('ValidationPipe', () => {
6565

6666
expect(ValidationPipe()('', { metaType: DTO })).rejects.toThrowError(BadRequestException);
6767
});
68+
69+
it('Should throw for a stringified JSON body.', () => {
70+
class DTO {
71+
@IsNotEmpty()
72+
@IsEmail()
73+
public email!: string;
74+
75+
@IsNotEmpty()
76+
public name!: string;
77+
}
78+
79+
expect(
80+
ValidationPipe()('{"email":"[email protected]","name":"Hello world"}', { metaType: DTO })
81+
).rejects.toThrowError(BadRequestException);
82+
});
6883
});

0 commit comments

Comments
 (0)