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() {