Skip to content

Commit

Permalink
fix handling of date objects (#2)
Browse files Browse the repository at this point in the history
* fix handling of date objects

* add repo links to package.json
  • Loading branch information
Hank Conn authored Jun 26, 2020
1 parent cd28af1 commit 09c8a4b
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 2 deletions.
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 9 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@swimlane/obfuscator",
"version": "1.1.0",
"version": "1.1.1",
"description": "Obfuscate objects based on a JSON Schema",
"main": "dist/index.js",
"typings": "dist/index.d.ts",
Expand Down Expand Up @@ -44,6 +44,14 @@
"json",
"schema"
],
"repository": {
"type": "git",
"url": "git+https://github.com/swimlane/obfuscator.git"
},
"bugs": {
"url": "https://github.com/swimlane/obfuscator/issues"
},
"homepage": "https://github.com/swimlane/obfuscator#readme",
"author": "Swimlane <[email protected]>",
"license": "AGPL-3.0",
"nyc": {
Expand Down
5 changes: 5 additions & 0 deletions src/Obfuscator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,11 @@ export class Obfuscator {
return newValue.map((nv, idx) => Obfuscator.unObfuscate(nv, prevValue[idx], replaceString));
}

// date objects are safe
if (newValue !== null && newValue instanceof Date) {
return newValue;
}

// unobfuscate values in an object
if (newValue !== null && typeof newValue === 'object' && prevValue !== null && typeof prevValue === 'object') {
const newObj = { ...newValue };
Expand Down
14 changes: 14 additions & 0 deletions tests/Obfuscator.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -334,6 +334,20 @@ describe('Obfuscator', () => {
expect(Obfuscator.unObfuscate(null, null)).to.be.null;
done();
});

it('should handle dates', done => {
const newDate = new Date();
const oldDate = new Date(new Date().getTime() - 1000);
const newVal = {
foo: Obfuscator.defaultReplaceString,
fizz: newDate
};
const oldVal = { foo: 'bar', fizz: oldDate };
const result = Obfuscator.unObfuscate(newVal, oldVal);
expect(result.fizz instanceof Date);
expect(result.fizz.getTime()).to.eq(newDate.getTime());
done();
});
});

describe('.predicateTypeFormat()', () => {
Expand Down

0 comments on commit 09c8a4b

Please sign in to comment.