-
Notifications
You must be signed in to change notification settings - Fork 25.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
BREAKING CHANGE: Forms [email] input coercion Forms [email] input value will be considered as true if it is defined with any value rather than false and 'false'. PR Close #42803
- Loading branch information
1 parent
db6cf7e
commit d5719c2
Showing
12 changed files
with
93 additions
and
39 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
/** | ||
* @license | ||
* Copyright Google LLC All Rights Reserved. | ||
* | ||
* Use of this source code is governed by an MIT-style license that can be | ||
* found in the LICENSE file at https://angular.io/license | ||
*/ | ||
|
||
/** Coerces a value (typically a string) to a boolean. */ | ||
export function coerceToBoolean(value: unknown): boolean { | ||
return typeof value === 'boolean' ? value : (value != null && value !== 'false'); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
/** | ||
* @license | ||
* Copyright Google LLC All Rights Reserved. | ||
* | ||
* Use of this source code is governed by an MIT-style license that can be | ||
* found in the LICENSE file at https://angular.io/license | ||
*/ | ||
import {coerceToBoolean} from '@angular/core/src/util/coercion'; | ||
|
||
{ | ||
describe('coerceToBoolean', () => { | ||
it('should coerce undefined to false', () => { | ||
expect(coerceToBoolean(undefined)).toBe(false); | ||
}); | ||
|
||
it('should coerce null to false', () => { | ||
expect(coerceToBoolean(null)).toBe(false); | ||
}); | ||
|
||
it('should coerce the empty string to true', () => { | ||
expect(coerceToBoolean('')).toBe(true); | ||
}); | ||
|
||
it('should coerce zero to true', () => { | ||
expect(coerceToBoolean(0)).toBe(true); | ||
}); | ||
|
||
it('should coerce the string "false" to false', () => { | ||
expect(coerceToBoolean('false')).toBe(false); | ||
}); | ||
|
||
it('should coerce the boolean false to false', () => { | ||
expect(coerceToBoolean(false)).toBe(false); | ||
}); | ||
|
||
it('should coerce the boolean true to true', () => { | ||
expect(coerceToBoolean(true)).toBe(true); | ||
}); | ||
|
||
it('should coerce the string "true" to true', () => { | ||
expect(coerceToBoolean('true')).toBe(true); | ||
}); | ||
|
||
it('should coerce an arbitrary string to true', () => { | ||
expect(coerceToBoolean('pink')).toBe(true); | ||
}); | ||
|
||
it('should coerce an object to true', () => { | ||
expect(coerceToBoolean({})).toBe(true); | ||
}); | ||
|
||
it('should coerce an array to true', () => { | ||
expect(coerceToBoolean([])).toBe(true); | ||
}); | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters