From 6f11e26f8914c71b19063c6ff7f020e3619ffbb4 Mon Sep 17 00:00:00 2001 From: Sander Rijken Date: Fri, 25 Sep 2015 23:57:47 +0200 Subject: [PATCH 1/2] Fix test case for Utils.stringify around exlusion behavior --- src/Utils-spec.ts | 28 ++++++++++++++++++++++------ 1 file changed, 22 insertions(+), 6 deletions(-) diff --git a/src/Utils-spec.ts b/src/Utils-spec.ts index fc03bec9..0ec662c4 100644 --- a/src/Utils-spec.ts +++ b/src/Utils-spec.ts @@ -23,7 +23,7 @@ describe('Utils', () => { expect(Utils.stringify([{one: afoo, two: afoo}])).toBe('[{"one":{"a":"foo"}}]'); }); - it('should exclude properties', () => { + describe('stringify', () => { var user:any = { id:1, name: 'Blake', @@ -37,11 +37,27 @@ describe('Utils', () => { } }; - expect(Utils.stringify(user)).toBe(JSON.stringify(user)); - expect(Utils.stringify(user, ['pAssword'])).toBe('{"id":1,"name":"Blake","passwordResetToken":"a reset token","myPasswordValue":"123456","myPassword":"123456","customValue":"Password","value":{}}'); - expect(Utils.stringify(user, ['*password'])).toBe('{"id":1,"name":"Blake","myPasswordValue":"123456","myPassword":"123456","customValue":"Password","value":{}}'); - expect(Utils.stringify(user, ['password*'])).toBe('{"id":1,"name":"Blake","passwordResetToken":"a reset token","myPasswordValue":"123456","customValue":"Password","value":{}}'); - expect(Utils.stringify(user, ['*password*'])).toBe('{"id":1,"name":"Blake","customValue":"Password","value":{}}'); + it('should behave like JSON.stringify', () => { + expect(Utils.stringify(user)).toBe(JSON.stringify(user)); + }); + + describe('with exclude pattern', () => { + it('pAssword', () => { + expect(Utils.stringify(user, ['pAssword'])).toBe('{"id":1,"name":"Blake","passwordResetToken":"a reset token","myPasswordValue":"123456","myPassword":"123456","customValue":"Password","value":{}}'); + }); + + it('*password', () => { + expect(Utils.stringify(user, ['*password'])).toBe('{"id":1,"name":"Blake","passwordResetToken":"a reset token","myPasswordValue":"123456","customValue":"Password","value":{}}'); + }); + + it('password*', () => { + expect(Utils.stringify(user, ['password*'])).toBe('{"id":1,"name":"Blake","myPasswordValue":"123456","myPassword":"123456","customValue":"Password","value":{}}'); + }); + + it('*password*', () => { + expect(Utils.stringify(user, ['*password*'])).toBe('{"id":1,"name":"Blake","customValue":"Password","value":{}}'); + }); + }); }); it('should stringify array', () => { From e1de8b13d657e1086a0d8692d1918e28630cd84e Mon Sep 17 00:00:00 2001 From: Sander Rijken Date: Fri, 25 Sep 2015 23:58:07 +0200 Subject: [PATCH 2/2] Fix exclusion patterns --- src/Utils.ts | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/Utils.ts b/src/Utils.ts index 9898d6fc..6b93db0b 100644 --- a/src/Utils.ts +++ b/src/Utils.ts @@ -133,15 +133,14 @@ export class Utils { pattern = pattern.substring(0, pattern.length - 1); } - if (startsWithWildcard && endsWithWildcard) return value.indexOf(pattern) !== -1; if (startsWithWildcard) - return value.lastIndexOf(pattern, 0) !== -1; + return value.lastIndexOf(pattern) === (value.length - pattern.length); if (endsWithWildcard) - return value.lastIndexOf(pattern) === (value.length - pattern.length); + return value.indexOf(pattern) === 0; return value === pattern; }