-
Notifications
You must be signed in to change notification settings - Fork 27.4k
fix($location): don't remove multiple slashes from urls #15359
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2453,9 +2453,9 @@ describe('$location', function() { | |
var locationUrl, locationUmlautUrl, locationIndexUrl; | ||
|
||
beforeEach(function() { | ||
locationUrl = new LocationHtml5Url('http://server/pre/', 'http://server/pre/', 'http://server/pre/path'); | ||
locationUmlautUrl = new LocationHtml5Url('http://särver/pre/', 'http://särver/pre/', 'http://särver/pre/path'); | ||
locationIndexUrl = new LocationHtml5Url('http://server/pre/index.html', 'http://server/pre/', 'http://server/pre/path'); | ||
locationUrl = new LocationHtml5Url('http://server/pre/', 'http://server/pre/', '#!'); | ||
locationUmlautUrl = new LocationHtml5Url('http://särver/pre/', 'http://särver/pre/', '#!'); | ||
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. Maybe consider adding tests for 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. BTW the changes in this beforeEach were only because the setup was actually wrong! The third parameter is supposed to be the hashbang prefix. |
||
locationIndexUrl = new LocationHtml5Url('http://server/pre/index.html', 'http://server/pre/', '#!'); | ||
}); | ||
|
||
it('should rewrite URL', function() { | ||
|
@@ -2480,6 +2480,10 @@ describe('$location', function() { | |
expect(parseLinkAndReturn(locationUrl, 'someIgnoredAbsoluteHref', '#test')).toEqual('http://server/pre/otherPath#test'); | ||
}); | ||
|
||
it('should cope with double slashes in the path', function() { | ||
expect(parseLinkAndReturn(locationUrl, 'http://server/pre///other/path')).toEqual('http://server/pre///other/path'); | ||
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 wonder if a more integration-style test that checks how the app URL is used to resolve a template would be useful? With this change, we still end up with multiple slashes in the URL, so we could still accidentally drop a path segment if we later parse it using 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'll look into it... Krzysztof also suggested that we need to deal with multiple leading backslashes too... 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. It's not just multiple backslashes. Basically
would be enough to fix the bug. That said, I don't know if the multiple slashes are worth preserving in the beginning of a path for Angular apps. Existing apps served on those would be broken without this patch, so there is no backwards-compatibility problem and it's hard to tell if accepting "//" would not cause further errors when resolving relative URLs for the app later on. Prohibiting that overall seems like a good, conservative choice. 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. OK, I agree that we may as well lock this down, rather than potentially passing the issue onto some other part of the code. We can always relax this error and do something similar to this PR, later, if people complain. |
||
}); | ||
|
||
|
||
it('should complain if no base tag present', function() { | ||
module(function($locationProvider) { | ||
|
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.
Do we need the extra leading
/
forslashCount > 1
?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.
Yes, because it gets stripped off at some other point in the code
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.
But don't we add it back 5 lines above with
locationObj.$$path = decodeURIComponent(slashes + match.pathname.substr(1))
?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.
It's complicated. Try it! Tests will fail :-)