This repository was archived by the owner on Apr 12, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 27.4k
fix($interpolate): use custom toString() function & fix(ngBind): use same json conversion as $interpolate #14715
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 |
---|---|---|
|
@@ -8,15 +8,7 @@ | |
/* global isFunction: false */ | ||
/* global noop: false */ | ||
/* global toJson: false */ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think this is not necessary any more (but it may have gone away in master anyway). |
||
|
||
function stringify(value) { | ||
if (value == null /* null/undefined */) { return ''; } | ||
switch (typeof value) { | ||
case 'string': return value; | ||
case 'number': return '' + value; | ||
default: return toJson(value); | ||
} | ||
} | ||
/* global $$stringify: false */ | ||
|
||
// Convert an index into the string into line/column for use in error messages | ||
// As such, this doesn't have to be efficient. | ||
|
This file contains hidden or 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 hidden or 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 hidden or 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 |
---|---|---|
|
@@ -46,6 +46,43 @@ describe('ngBind*', function() { | |
expect(element.text()).toEqual('-0false'); | ||
})); | ||
|
||
they('should jsonify $prop', [[{a: 1}, '{"a":1}'], [true, 'true'], [false, 'false']], function(prop) { | ||
inject(function($rootScope, $compile) { | ||
$rootScope.value = prop[0]; | ||
element = $compile('<div ng-bind="value"></div>')($rootScope); | ||
$rootScope.$digest(); | ||
expect(element.text()).toEqual(prop[1]); | ||
}); | ||
}); | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would add a test with a custom |
||
it('should use custom toString when present', inject(function($rootScope, $compile) { | ||
$rootScope.value = { | ||
toString: function() { | ||
return 'foo'; | ||
} | ||
}; | ||
element = $compile('<div ng-bind="value"></div>')($rootScope); | ||
$rootScope.$digest(); | ||
expect(element.text()).toEqual('foo'); | ||
})); | ||
|
||
it('should NOT use toString on array objects', inject(function($rootScope, $compile) { | ||
$rootScope.value = []; | ||
element = $compile('<div ng-bind="value"></div>')($rootScope); | ||
$rootScope.$digest(); | ||
expect(element.text()).toEqual('[]'); | ||
})); | ||
|
||
|
||
it('should NOT use toString on Date objects', inject(function($rootScope, $compile) { | ||
$rootScope.value = new Date(2014, 10, 10, 0, 0, 0); | ||
element = $compile('<div ng-bind="value"></div>')($rootScope); | ||
$rootScope.$digest(); | ||
expect(element.text()).toBe(JSON.stringify($rootScope.value)); | ||
expect(element.text()).not.toEqual($rootScope.value.toString()); | ||
})); | ||
|
||
|
||
it('should one-time bind if the expression starts with two colons', inject(function($rootScope, $compile) { | ||
element = $compile('<div ng-bind="::a"></div>')($rootScope); | ||
$rootScope.a = 'lucas'; | ||
|
This file contains hidden or 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 hidden or 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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am not sure I am a big fan of not
toString
ifying Dates.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
They were jsonified before and that output is more universal than toString, which produces an American date format while jsonified is ISO.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
They were JSONified in
$interpolate
, buttoString
ified inngBind
. Since we are making the two consistent, we need to break one of them.But you convicned me: a universal format is better than forcing American English for all users.
(For some reason, I was under the impression
toString()
returned a localized string...)There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I thought that too (localized string) and might have written that somewhere.