From d29683c3b0a37a91cade4df97aa35a3c922e66fe Mon Sep 17 00:00:00 2001 From: Caitlin Potter Date: Thu, 17 Jul 2014 21:44:48 -0400 Subject: [PATCH] fix(input): by default, do not trim input[type=password] values Do not trim input[type=password] values BREAKING CHANGE: Previously, input[type=password] would trim values by default, and would require an explicit ng-trim="false" to disable the trimming behaviour. After this CL, ng-trim no longer effects input[type=password], and will never trim the password value. --- src/ng/directive/input.js | 5 +++-- test/ng/directive/inputSpec.js | 24 ++++++++++++++++++++++++ 2 files changed, 27 insertions(+), 2 deletions(-) diff --git a/src/ng/directive/input.js b/src/ng/directive/input.js index f0acb2739d4a..bde1d8373017 100644 --- a/src/ng/directive/input.js +++ b/src/ng/directive/input.js @@ -908,6 +908,7 @@ function addNativeHtml5Validators(ctrl, validatorName, badFlags, ignoreFlags, va function textInputType(scope, element, attr, ctrl, $sniffer, $browser) { var validity = element.prop(VALIDITY_STATE_PROPERTY); var placeholder = element[0].placeholder, noevent = {}; + var type = element[0].type.toLowerCase(); ctrl.$$validityState = validity; // In composition mode, users are still inputing intermediate text buffer, @@ -942,8 +943,8 @@ function textInputType(scope, element, attr, ctrl, $sniffer, $browser) { // By default we will trim the value // If the attribute ng-trim exists we will avoid trimming - // e.g. - if (!attr.ngTrim || attr.ngTrim !== 'false') { + // If input type is 'password', the value is never trimmed + if (type !== 'password' && (!attr.ngTrim || attr.ngTrim !== 'false')) { value = trim(value); } diff --git a/test/ng/directive/inputSpec.js b/test/ng/directive/inputSpec.js index bf6bd70d2ecc..a3e1689f793c 100644 --- a/test/ng/directive/inputSpec.js +++ b/test/ng/directive/inputSpec.js @@ -2967,6 +2967,30 @@ describe('input', function() { expect(scope.items[0].selected).toBe(false); }); }); + + + describe('password', function() { + // Under no circumstances should input[type=password] trim inputs + it('should not trim if ngTrim is unspecified', function() { + compileInput(''); + changeInputValueTo(' - - untrimmed - - '); + expect(scope.password.length).toBe(' - - untrimmed - - '.length); + }); + + + it('should not trim if ngTrim !== false', function() { + compileInput(''); + changeInputValueTo(' - - untrimmed - - '); + expect(scope.password.length).toBe(' - - untrimmed - - '.length); + }); + + + it('should not trim if ngTrim === false', function() { + compileInput(''); + changeInputValueTo(' - - untrimmed - - '); + expect(scope.password.length).toBe(' - - untrimmed - - '.length); + }); + }); }); describe('NgModel animations', function() {