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', () => { 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; }