New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix(aio): strip leading slashes from path (and improve DRY-ness) #16238
fix(aio): strip leading slashes from path (and improve DRY-ness) #16238
Conversation
This is quite likely to break https://github.com/angular/angular/blob/master/aio/src/app/embedded/current-location.component.ts#L10 |
But we could refactor that too, to use the |
}); | ||
|
||
describe('go', () => { | ||
it('should update the location', () => { | ||
describe('pathStream', () => { |
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 is just currentPath
- no need for the stream thingy
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.
Was keeping in-line with the urlStream
above, but I'll change them both 😃
@@ -14,21 +14,22 @@ export class LocationService { | |||
private readonly urlParser = document.createElement('a'); | |||
private urlSubject = new Subject<string>(); | |||
currentUrl = this.urlSubject | |||
.map(url => this.stripSlashes(url)) |
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.
This will not strip trailing slashes from URLs that have a query or a hash. E.g. /a/b/c/?some=value
@@ -122,7 +113,7 @@ export class LocationService { | |||
return true; | |||
} | |||
|
|||
this.go(this.stripLeadingSlashes(relativeUrl)); | |||
this.go(this.stripSlashes(relativeUrl)); |
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.
perhaps we ought to be doing the slash stripping in the go method, instead?
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.
Sounds reasonable.
@@ -3,12 +3,11 @@ import { BehaviorSubject } from 'rxjs/BehaviorSubject'; | |||
export class MockLocationService { | |||
urlSubject = new BehaviorSubject<string>(this.initialUrl); |
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 to strip slashes here then?
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 are not stripping slashes anywhere in this mock implementation. I assume it is the user's responsibility to provide URLs without slashes.
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 seemed like such a simple refactoring eh?
We need to fix the CurrentLocationComponent
usage of this service (and maybe add an e2e test to check); and I think there is a problem with stripping trailing slashes when the url contains a query or a hash.
const service: LocationService = injector.get(LocationService); | ||
let url: string; | ||
|
||
location.simulatePopState('///some/url///'); |
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.
Now try:
location.simulatePopState('///some/url///?some=query');
|
||
const urls = []; | ||
service.currentUrl.subscribe(url => urls.push(url)); | ||
location.simulatePopState('/initial/url1?foo=bar'); |
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.
location.simulatePopState('///some/url///?some=query');
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 like the latest changes 👍
Still need to fix the trailing slashes issue
@petebd, I think I addressed all comments. PTAL |
I'll squash and re-push just to be sure - before merging |
I pushed another commit with more tests after you approved 😁 |
8a9f565
to
1f0fbb9
Compare
Previously, the path returned by `LocationService.path()` preserved leading slashes, which resulted in requests with consequtive slashes in the URL. Such requests would fail (with a 404) on staging. This commit fixes it, by removing leading slashes from the path. It also refactors `LocationService` a bit, converting path to an observable, `currentPath` (similar to `currentUrl`), and applies certain clean-ups (e.g. stripping slashes, query, hash) in one place, which simplifies consumption. Closes angular#16230
1f0fbb9
to
781dce2
Compare
Fixed linting issues and squashed. |
Great. Let's merge |
…ular#16238) Previously, the path returned by `LocationService.path()` preserved leading slashes, which resulted in requests with consequtive slashes in the URL. Such requests would fail (with a 404) on staging. This commit fixes it, by removing leading slashes from the path. It also refactors `LocationService` a bit, converting path to an observable, `currentPath` (similar to `currentUrl`), and applies certain clean-ups (e.g. stripping slashes, query, hash) in one place, which simplifies consumption. Closes angular#16230
…ular#16238) Previously, the path returned by `LocationService.path()` preserved leading slashes, which resulted in requests with consequtive slashes in the URL. Such requests would fail (with a 404) on staging. This commit fixes it, by removing leading slashes from the path. It also refactors `LocationService` a bit, converting path to an observable, `currentPath` (similar to `currentUrl`), and applies certain clean-ups (e.g. stripping slashes, query, hash) in one place, which simplifies consumption. Closes angular#16230
This issue has been automatically locked due to inactivity. Read more about our automatic conversation locking policy. This action has been performed automatically by a bot. |
Previously, the path returned by
LocationService.path()
preserved leading slashes, which resulted in requests with consequtive slashes in the URL. Such requests would fail (with a 404) on staging.This commit fixes it, by removing leading slashes from the path. It also refactors
LocationService
a bit, converting path to an observable,currentPath
(similar tocurrentUrl
), and applies certain clean-ups (e.g. stripping slashes, query, hash) in one place, which simplifies consumption.This is an alternative to #16230.