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($routeProvider): do not deep-copy route definition objects #14750
Closed
Closed
Changes from 1 commit
Commits
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
'use strict'; | ||
|
||
describe('$route', function() { | ||
fdescribe('$route', function() { | ||
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. fdescribe |
||
var $httpBackend, | ||
element; | ||
|
||
|
@@ -900,6 +900,87 @@ describe('$route', function() { | |
}); | ||
|
||
|
||
it('should not get affected by modifying the route definition object after route registration', | ||
function() { | ||
module(function($routeProvider) { | ||
var rdo = {}; | ||
|
||
rdo.templateUrl = 'foo.html'; | ||
$routeProvider.when('/foo', rdo); | ||
|
||
rdo.templateUrl = 'bar.html'; | ||
$routeProvider.when('/bar', rdo); | ||
}); | ||
|
||
inject(function($location, $rootScope, $route) { | ||
$location.path('/bar'); | ||
$rootScope.$digest(); | ||
expect($location.path()).toBe('/bar'); | ||
expect($route.current.templateUrl).toBe('bar.html'); | ||
|
||
$location.path('/foo'); | ||
$rootScope.$digest(); | ||
expect($location.path()).toBe('/foo'); | ||
expect($route.current.templateUrl).toBe('foo.html'); | ||
}); | ||
} | ||
); | ||
|
||
|
||
it('should use the property values of the passed in route definition object directly', | ||
function() { | ||
var $routeProvider; | ||
|
||
module(function(_$routeProvider_) { | ||
$routeProvider = _$routeProvider_; | ||
}); | ||
|
||
inject(function($location, $rootScope, $route, $sce) { | ||
var sceWrappedUrl = $sce.trustAsResourceUrl('foo.html'); | ||
$routeProvider.when('/foo', {templateUrl: sceWrappedUrl}); | ||
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. why is the 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. Because I couldn't access |
||
|
||
$location.path('/foo'); | ||
$rootScope.$digest(); | ||
expect($location.path()).toBe('/foo'); | ||
expect($route.current.templateUrl).toBe(sceWrappedUrl); | ||
}); | ||
} | ||
); | ||
|
||
|
||
it('should support custom `$sce` implementations', function() { | ||
function MySafeResourceUrl(val) { | ||
var self = this; | ||
this._val = val; | ||
this.getVal = function() { | ||
return (this !== self) ? null : this._val; | ||
}; | ||
} | ||
|
||
var $routeProvider; | ||
|
||
module(function($provide, _$routeProvider_) { | ||
$routeProvider = _$routeProvider_; | ||
|
||
$provide.decorator('$sce', function($delegate) { | ||
$delegate.trustAsResourceUrl = function(url) { return new MySafeResourceUrl(url); }; | ||
$delegate.getTrustedResourceUrl = function(v) { return v.getVal(); }; | ||
$delegate.valueOf = function(v) { return v.getVal(); }; | ||
return $delegate; | ||
}); | ||
}); | ||
|
||
inject(function($location, $rootScope, $route, $sce) { | ||
$routeProvider.when('/foo', {templateUrl: $sce.trustAsResourceUrl('foo.html')}); | ||
|
||
$location.path('/foo'); | ||
$rootScope.$digest(); | ||
expect($location.path()).toBe('/foo'); | ||
expect($sce.valueOf($route.current.templateUrl)).toBe('foo.html'); | ||
}); | ||
}); | ||
|
||
|
||
describe('redirection', function() { | ||
it('should support redirection via redirectTo property by updating $location', function() { | ||
module(function($routeProvider) { | ||
|
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.
can't you use this one:
angular.js/src/Angular.js
Line 941 in 3ba29c4
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.
Since we are in a external module, we need to copy it. I started by copying that, but then removed the stuff that didn't seem relevant.
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.
ok. sgtm.
On Thu, Jun 9, 2016 at 2:25 PM Georgios Kalpakas [email protected]
wrote:
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.
Isn't this another case where we should split the shared function into its own file so that we can reuse it in multiple modules?
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.
We could, but I wouldn't.
We don't need the exact same function. The one from core can shallow-copy arrays as well, ignores
$$
prefixed properties and supports passing your owndst
object, which properties are shallow-copied onto. We we don't need any of that.