Skip to content
This repository was archived by the owner on Aug 1, 2020. It is now read-only.

Commit fdc9035

Browse files
merge: release 1.0.1 (#17)
2 parents 420fd13 + 4485ecc commit fdc9035

File tree

5 files changed

+36
-5
lines changed

5 files changed

+36
-5
lines changed

CHANGELOG.md

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,18 @@
22

33
_This changelog follows the [keep a changelog][keep-a-changelog]_ format to maintain a human readable changelog.
44

5-
## [1.0.0][v1.0.0] - 2020-07-31 [BREAKING CHANGE]
5+
## [1.0.1][v1.0.1] - 2020-07-31
66

77
> This is the **final release of the library**, if you lack some functionality please use [class-transformer][ct] and [class-validator][cv] instead.
88
99
#### Fixed
1010

11+
- sanitization won't skip properties with empty string values anymore (`''`)
12+
13+
## [1.0.0][v1.0.0] - 2020-07-31 [BREAKING CHANGE]
14+
15+
#### Fixed
16+
1117
- passing `{ each: true }` into decorators don't crashes the library anymore
1218
- fixed security warning due to out-of-date dev dependencies
1319

@@ -50,6 +56,7 @@ _This changelog follows the [keep a changelog][keep-a-changelog]_ format to main
5056

5157
Initial version.
5258

59+
[v1.0.0]: https://github.com/typestack/class-sanitizer/compare/v1.0.0...v1.0.1
5360
[v1.0.0]: https://github.com/typestack/class-sanitizer/compare/v0.0.5...v1.0.0
5461
[v0.0.5]: https://github.com/typestack/class-sanitizer/compare/v0.0.4...v0.0.5
5562
[v0.0.4]: https://github.com/typestack/class-sanitizer/compare/v0.0.3...v0.0.4

package-lock.json

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "class-sanitizer",
3-
"version": "1.0.0",
3+
"version": "1.0.1",
44
"description": "Decorator based class property sanitation in Typescript.",
55
"license": "MIT",
66
"author": {

src/sanitizer.class.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ export class Sanitizer {
120120
public sanitize<T = Record<string, any>>(classInstance: InstanceType<any>): T {
121121
this.metadataStorage
122122
.getSanitizeMetadatasForClassInstance(classInstance)
123-
.filter(metadata => !!classInstance[metadata.propertyName])
123+
.filter(mt => classInstance[mt.propertyName] !== undefined && classInstance[mt.propertyName] !== null)
124124
.forEach(metadata => {
125125
/** If `each` is set we validate the values of the array. */
126126
if (metadata.each) {

testing/basic-functionality.spec.ts

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { defaultMetadataStorage } from '../src/default-storage.const';
2-
import { Trim, Ltrim, Rtrim, SanitizeNested } from '../src/decorators';
2+
import { Trim, Ltrim, Rtrim, ToInt, SanitizeNested } from '../src/decorators';
33
import { sanitize, Sanitizer, sanitizeAsync } from '../src';
44

55
describe('Basic Functionality', () => {
@@ -109,4 +109,28 @@ describe('Basic Functionality', () => {
109109

110110
expect(result).toEqual(input);
111111
});
112+
113+
it(`should skip null and undefined properties but not ''`, () => {
114+
class TestClass {
115+
@ToInt()
116+
emptyStringValue: string;
117+
118+
@ToInt()
119+
undefinedValue: string;
120+
121+
@ToInt()
122+
nullValue: string;
123+
}
124+
125+
const instance = new TestClass();
126+
instance.emptyStringValue = '';
127+
instance.undefinedValue = undefined;
128+
instance.nullValue = null;
129+
130+
sanitize(instance);
131+
132+
expect(instance.emptyStringValue).toBeNaN();
133+
expect(instance.undefinedValue).toBeUndefined();
134+
expect(instance.nullValue).toBeNull();
135+
});
112136
});

0 commit comments

Comments
 (0)