Skip to content
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

Merged
merged 1 commit into from Apr 21, 2017

Conversation

gkalpak
Copy link
Member

@gkalpak gkalpak commented Apr 21, 2017

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.

This is an alternative to #16230.

@gkalpak gkalpak added comp: aio action: review The PR is still awaiting reviews from at least one requested reviewer labels Apr 21, 2017
@gkalpak gkalpak added this to REVIEW in docs-infra Apr 21, 2017
@petebacondarwin
Copy link
Member

@petebacondarwin
Copy link
Member

But we could refactor that too, to use the async filter etc.

});

describe('go', () => {
it('should update the location', () => {
describe('pathStream', () => {
Copy link
Member

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

Copy link
Member Author

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))
Copy link
Member

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));
Copy link
Member

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?

Copy link
Member Author

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);
Copy link
Member

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?

Copy link
Member Author

@gkalpak gkalpak Apr 21, 2017

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.

Copy link
Member

@petebacondarwin petebacondarwin left a 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.

@petebacondarwin petebacondarwin added action: cleanup The PR is in need of cleanup, either due to needing a rebase or in response to comments from reviews and removed action: review The PR is still awaiting reviews from at least one requested reviewer labels Apr 21, 2017
const service: LocationService = injector.get(LocationService);
let url: string;

location.simulatePopState('///some/url///');
Copy link
Member

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');
Copy link
Member

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');

Copy link
Member

@petebacondarwin petebacondarwin left a 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

@gkalpak
Copy link
Member Author

gkalpak commented Apr 21, 2017

@petebd, I think I addressed all comments. PTAL

@petebacondarwin
Copy link
Member

I'll squash and re-push just to be sure - before merging

@gkalpak
Copy link
Member Author

gkalpak commented Apr 21, 2017

I pushed another commit with more tests after you approved 😁

@gkalpak gkalpak force-pushed the fix-aio-remove-extraneous-slash branch from 8a9f565 to 1f0fbb9 Compare April 21, 2017 17:07
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
@gkalpak gkalpak force-pushed the fix-aio-remove-extraneous-slash branch from 1f0fbb9 to 781dce2 Compare April 21, 2017 17:09
@gkalpak
Copy link
Member Author

gkalpak commented Apr 21, 2017

Fixed linting issues and squashed.

@mary-poppins
Copy link

The angular.io preview for 781dce2 is available here.

@petebacondarwin
Copy link
Member

Great. Let's merge

@petebacondarwin petebacondarwin added action: merge The PR is ready for merge by the caretaker and removed action: cleanup The PR is in need of cleanup, either due to needing a rebase or in response to comments from reviews labels Apr 21, 2017
@petebacondarwin petebacondarwin moved this from REVIEW to MERGE in docs-infra Apr 21, 2017
@mhevery mhevery merged commit 9c1318d into angular:master Apr 21, 2017
@gkalpak gkalpak deleted the fix-aio-remove-extraneous-slash branch April 21, 2017 20:38
@petebacondarwin petebacondarwin removed this from MERGE in docs-infra Apr 22, 2017
asnowwolf pushed a commit to asnowwolf/angular that referenced this pull request Aug 11, 2017
…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
juleskremer pushed a commit to juleskremer/angular that referenced this pull request Aug 28, 2017
…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
@angular-automatic-lock-bot
Copy link

This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.

@angular-automatic-lock-bot angular-automatic-lock-bot bot locked and limited conversation to collaborators Sep 11, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
action: merge The PR is ready for merge by the caretaker cla: yes
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants